For anyone who has issues with hands randomly flipping 180 degrees or flipping when turning the hand(Over-turning), this is the fix for the script(Adds checks for rotation): private void PhysicsMove() { // Position var positionWithOffset = _followTarget.TransformPoint(positionOffset); var distance = Vector3.Distance(positionWithOffset, transform.position); _body.velocity = (positionWithOffset - transform.position).normalized * (followSpeed * distance); // Rotation var rotationWithOffset = _followTarget.rotation * Quaternion.Euler(rotationOffset); var q = rotationWithOffset * Quaternion.Inverse(_body.rotation); q.ToAngleAxis(out float angle, out Vector3 axis); if (Mathf.Abs(axis.magnitude) != Mathf.Infinity) { if (angle > 180.0f) { angle -= 360.0f; } _body.angularVelocity = axis * (angle * Mathf.Deg2Rad * rotateSpeed); } }
I fixed the hands a little, I added a time.deltatime to body.velocity = (positionWithOffset - transform.position).normalized * followSpeed * distance * Time.deltaTime; and body.angularVelocity = angle * axis * Mathf.Deg2Rad * rotateSpeed * Time.deltaTime; . that made the hands more stable, but the hands were moving too slow so I changed Follow speed to 1800 and rotate speed to 6000. You also should move the player inside XR rig so if you walk around the hands are more stable.
instead of: body.velocity = (positionWithOffset - transform.position).normalized* followSpeed * distance * Time.deltaTime try: body.velocity = (positionWithOffset - transform.position) / Time.fixedTime this should give the velocity needed to get to the target in one frame...
Bro, thank you for all these videos, I've been working with Unity for 4 years now, and recently got a Quest 2 and wanted to start developing for VR, your videos are super helpfull. Thanks again!
I know it's not really related to this video but I'd love a video about how to properly make tools (like weapons or actual tools) in VR which you can pick up and then use all the inputs from the controller that's holding it to activate something. I know that you can easily do that with the activate-function, but that's only for the trigger and I'd also want to use the A and B Button or the stick. Anyways great video!
No clue, if people are having issues with this, but the adding the absolute offset didn't quite match the correct position for me. The position only matched at a specific controller position and rotation. So to calculate the correct target position, I used "Vector3 targetPos = _followTarget.TransformPoint(positionOffset)" , where positionOffset is the local offset to the hands from the controller. TransformPoint calculates the world position from a local position.
10:44 what's the point of calculating the vector between the position of the gameobject (transform.position) and the position of the target in line 58, and then normalizing it if it's to remultiply it by its distance behind that we calculated in line 57. Because then we find the non-normalized vector if we multiply it by its distance
Hi Justin, thanks for the detailed Video. I'm using oculus integration sdk and in my ovrhands, i have attached colliders and the tracking works really well. However, I am unable to manage grab and other interactions like earlier.
Awesome bro! i use my own 3d hand models and it works just fine! i had one little issue in the other tutorial on how to animate the hands. i did everything but it just didn't work for some reason. but i fixed it i just watched an other tutorial and then i came back to this tutorial. im exited for the hand pose tutorial for when you grab objects! see ya soon
I have no idea if I'll get a response, but I got an issue that came from this. I followed all the tutorials about getting the hands to be rotated correctly. After adding the physics, the hands will not rotate correctly, regardless of what I do in the inspector. Any help would be appreciated, the code is almost identical to this video outside of some minor changes. Plus the code for the physics grab.
I had a trouble when I tried to attach the hands to the controllers,. It was solved when I replace the Update() function with FixedUpdate() function. BTW, Thanks for the great videos with super high quality!!
Love the tutorials! I'm having one slight issue though and I'm not sure if I did something wrong. The rotation seems to be too slow and if I turn my hand relatively fast its very obvious that the rotation is slow. I have all the same variable values but the hand still seems to rotate too slow. If I turn up the rotation speed I get the vibrating that you talked about. Thank you!
I'm in the works of learning VR game design using all of your tutorials and loving them!! Having a slit issue with floats converting the vector3 with this exact code. Would you have any idea on how to get around this issue?
For some reason when I click in the hierarchy to go to prefabs and unpack the XR Rig. Prefabs does not show up. It’s very strange, I don’t know what I’m doing wrong or what the issue is. These tutorials are awesome though! Keep up the good work!
The distance is calculated between the followObject and the transform.position. But the relative ration is calculated between the followObject and the _body. Shouldn’t these two be consistent in using the same pair?
Thanks for the tutorials. They help a lot! I am having an issue where the hands are not rotated properly to match the controller rotation, EVEN if I rotate them or the controllers in the editor. Can you help me with this? Thanks!
I've just followed this tutorial but now my hands don't animate or pick up objects from the last tutorial :( What have I done!? Also love the tutorials thank you for helping me learn!
Just tried this out, one issue I've run into is that when I'm rotating my left hand when it hits a certain degrees it rotates the opposite direction till it reaches where I was, any fix for that?
Yea there's a pretty easy fix for that! After the .ToAngleAxis() method do a check to see if the angle in degrees is greater than 180. If so, then subtract 360 from that number. This will always give you a range between -180 and 180 and should fix any weird over-rotation.
@@JustinPBarnett Hey Justin, I'm having the same over-rotation issue. Could you please tell me how to check the angle in degrees? I'm looking at the .ToAngleAxis method in my script, but I don't see any area where it shows angle in degrees or how to calculate it. I've been searching for a solution. Thanks!
@@sillyoldbear5379 Had the same problem and implemented his solution. The .ToAngleAxis function has that part "out float angle" - that variable "angle" is being set by the function, and is the difference in the angles of the two objects. If the value of it is greater than 180, you want to subtract 360 from it so that it stays within -180 to 180. So the code becomes: q.ToAngleAxis(out float angle, out Vector3 axis); if(angle > 180.0f) { angle -= 360.0f; } _body.angularVelocity = axis * (angle * Mathf.Deg2Rad * rotateSpeed); It just adds one extra step between the two lines. I'm certainly not an expert, but that is what worked for me!
Is this still nessacry relevant to your 2022 video where the hands are children of the controllers I'm running into a lot of issues after following that video and then onto this one do i need the follow and rotation if they just stay as children under the controller
Hi there, great video! Everything works fine except for one small thing: when the hands collide with a box collider they take a lot of time to return the right position (the follow target one) any idea to solve this?
Could this be used to interact with other humanoid models? For example if you had a human model with a rig (from blender) and an animation where said human tried to punch you, could you effectively grab its arm as if you were fighting against it to stop it punching you?
How to get the velocity of Left and Right from controller movement ? Action mapping gives zero every time, except one but it's velocity tracking from either controller.
At first, thanks for your tutorials. I animated the hands with your older video and tried to implement the physics from this video. The physics work for the most part but the animation is gone. How can i add the animation again?
@@JustinPBarnett The files are still there. The Animation ist just not happening when I pres the buttons. I just implemented everything from this video after i completed the animated hands videos and did not delete anything.
@@JustinPBarnett found it now. The Speed was set to 0 somehow. Went through everything to find it. But thanks anyway. Now i have to solve my problem with the IK. My Camera is stuck to the ground somehow :)
I tried making these hands, and the hands are far away from the actual controllers, and the hands float up and down slowly like 0 gravity, and sometimes they collide they start flying everywhere, but the controlling of the hand kinda works Edit: Fixed it.
You'd get some weird physics effects because the hands will be teleported to where your controller is every frame instead of moving there by physics, so eventually you'd have your hands teleport inside of something when you tried to interact with it and that'd cause things to fly off sporadically
You can try it that way! I haven’t given it a shot so don’t know if it would work when the hand animates. Let me know what you find out! I’m curious cause that’d be much easier
@@JustinPBarnett i think he means just add colliders so you can interact, no animations, i also need something like this because my hands are just cubes i just need them to collide and pick up
I didn't have the same issue, but a similar issue, go back and look at his hand script and make sure yours is 100% exactly like his at the last portion of when he shows his final code. There's a part where he replaces a variable, I missed it on one thing and was having minor bugs as well
video worked great! but i do have some bugs i was hoping you could help with, im using a locomotion system which does continuous moving and turning, but if i try and move forward my hand gets in the way, meaning i either have to stretch my arm out so i can move forwards or just live with the fact i cant move forwards, also my hands sometimes collides with my own body from the xr rig, meaning it launches me out of the map, i also had this problem with my grab-able, which is a sphere, any help?
@@ATiredArchivist make sure animation speed is more than 0 and youre second problemn edit project setting physics scroll to the bottom and uncheck youre body layer or make a body layer for youre xr rig and hands and grabable layer and unmark layer collosion and it will be fixed also sorry for bad english
Hey, there's a good chance you will not have time to read this but If you do, I would like to see a tutorial on stabbing in vr. I 100% understand If you won't be able to do one.