Тёмный

How to Make Physics-Based Hands in Unity XR 

Justin P Barnett
Подписаться 39 тыс.
Просмотров 31 тыс.
50% 1

Опубликовано:

 

15 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 136   
@Piepop101
@Piepop101 2 года назад
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); } }
@JustinPBarnett
@JustinPBarnett 2 года назад
Thanks!
@alexs7023
@alexs7023 2 года назад
Life saver, thank you so much
@juandicruck
@juandicruck 2 года назад
Good samaritan
@rgi2696
@rgi2696 10 месяцев назад
I was looking for that for smth like 2 days! I love u dude! I mean, not fr But if u don't have boyfriend/girlfriend then u know...
@nullname68
@nullname68 3 года назад
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.
@JustinPBarnett
@JustinPBarnett 2 года назад
Thanks!
@titanstudios6722
@titanstudios6722 2 года назад
I tried doing that but it is still really slow
@David-gu8hv
@David-gu8hv 2 года назад
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...
@stargazerbr_yt
@stargazerbr_yt 2 года назад
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!
@JustinPBarnett
@JustinPBarnett 2 года назад
You're very welcome!
@armandecourtot4409
@armandecourtot4409 3 года назад
i hope you upload that next video, i really need to know how to not make my hands just phase through objects. AWESOME VIDEOS bro keep up the work
@JustinPBarnett
@JustinPBarnett 3 года назад
Soon!!
@b3armonk
@b3armonk 3 года назад
Will look forward to part 2!
@JustinPBarnett
@JustinPBarnett 2 года назад
Still waiting 😂😂😂
@JustinPBarnett
@JustinPBarnett 3 года назад
What video/tutorial do you want to see next?! Reply to this comment and let me know! 👇
@thebutterappletutorials6553
@thebutterappletutorials6553 3 года назад
After the hand videos, would love to see a physics body!! Or a full-body sorta rig at some point!
@JustinPBarnett
@JustinPBarnett 3 года назад
@@thebutterappletutorials6553 absolutely!! you got it!
@thebutterappletutorials6553
@thebutterappletutorials6553 3 года назад
@@JustinPBarnett Yesss!!!
@matteomeysel
@matteomeysel 3 года назад
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!
@JustinPBarnett
@JustinPBarnett 3 года назад
Good idea!! I'm definitely going to do a VR gun video in the future! probably after all these hand tutorials
@nohandlearchive
@nohandlearchive 2 года назад
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.
@JustinPBarnett
@JustinPBarnett 3 года назад
Download the Project (for FREE): www.vrcreators.io/codedownloads
@mariusv9872
@mariusv9872 2 года назад
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
@hiddespaander749
@hiddespaander749 3 года назад
Really need a part 2
@JustinPBarnett
@JustinPBarnett 2 года назад
The most requested video by far 😅
@alekjatuszyk4976
@alekjatuszyk4976 3 года назад
i have looked for tutorial like this for sooooooo long. you have saved me! thanks a lot
@JustinPBarnett
@JustinPBarnett 3 года назад
You're welcome!
@rahulkumarray7468
@rahulkumarray7468 8 месяцев назад
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.
@loukenart
@loukenart 3 года назад
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
@JustinPBarnett
@JustinPBarnett 3 года назад
Glad you got it working! Yea some of the most recent updates have broken the hand tracking a bit. Hard to keep up with all the changes Unity makes 😅
@TSalispahic
@TSalispahic Год назад
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.
@趙胤筌
@趙胤筌 2 года назад
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!!
@atomicalgaming
@atomicalgaming 2 года назад
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!
@JustinPBarnett
@JustinPBarnett 2 года назад
Set the rigidbody.maxAngularVelocity = float.PositiveInifinity;
@atomicalgaming
@atomicalgaming 2 года назад
@@JustinPBarnett Awesome thank you!
@ParksInYourPocket
@ParksInYourPocket 3 года назад
Haven't watched all your videos yet. Has the second part of this come out?
@JustinPBarnett
@JustinPBarnett 3 года назад
Not yet!
@lucasmartinic2039
@lucasmartinic2039 3 года назад
Great content man, thanks!
@JustinPBarnett
@JustinPBarnett 3 года назад
sure thing!! appreciate ya
@Zippiii
@Zippiii 3 года назад
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?
@JustinPBarnett
@JustinPBarnett 2 года назад
Great to hear! Join the discord if you're still having issues and we can help you troubleshoot!
@theytpguy7658
@theytpguy7658 2 года назад
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!
@JustinPBarnett
@JustinPBarnett 2 года назад
You can only unpack prefabs, so if it's not blue you won't see a prefabs option
@watermelonrolls
@watermelonrolls 3 года назад
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?
@JustinPBarnett
@JustinPBarnett 3 года назад
Yea good catch! I fixed this in my Inverse Kinematics video
@genofelice6034
@genofelice6034 Год назад
I can't seem to find the additional videos for physics hands
@martinstatelov3969
@martinstatelov3969 2 года назад
Great tutorials :)
@JustinPBarnett
@JustinPBarnett 2 года назад
Thanks!
@satirical_snake
@satirical_snake 2 года назад
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!
@JustinPBarnett
@JustinPBarnett 2 года назад
You're welcome! Are you making sure to adjust the offsets and not the actual hands?
@satirical_snake
@satirical_snake 2 года назад
Thank you! It worked
@fashvr9961
@fashvr9961 Год назад
Hey Justin, how would you combine this with ik
@Lonely-_-Beaver
@Lonely-_-Beaver 2 года назад
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!
@JustinPBarnett
@JustinPBarnett 2 года назад
Join the discord and we can help you troubleshoot!
@CrewsterEX
@CrewsterEX 2 года назад
You have to change the Animation Speed on the Hand script because you change the float from speed to AnimationSpeed so it defaults to 0.
@thebutterappletutorials6553
@thebutterappletutorials6553 3 года назад
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?
@JustinPBarnett
@JustinPBarnett 3 года назад
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.
@thebutterappletutorials6553
@thebutterappletutorials6553 3 года назад
@@JustinPBarnett Works like a charm thank you!
@JustinPBarnett
@JustinPBarnett 3 года назад
@@thebutterappletutorials6553 perfect!!
@sillyoldbear5379
@sillyoldbear5379 3 года назад
@@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!
@Bryggyth
@Bryggyth 3 года назад
​@@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!
@joshuakelly1198
@joshuakelly1198 2 года назад
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
@Official_KB_Studios
@Official_KB_Studios 2 года назад
Hey man are you ever going to make procedurally animated hand tutorial?
@JustinPBarnett
@JustinPBarnett 2 года назад
Yes!
@Clamaz
@Clamaz 2 года назад
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?
@tkpmonke
@tkpmonke 2 года назад
my hands are jittering alot can you help me with this
@RealityScapeStudios
@RealityScapeStudios 2 года назад
Did the second video come out about objects in your hands?
@JustinPBarnett
@JustinPBarnett 2 года назад
Not yet 😬
@tomtomh5
@tomtomh5 3 года назад
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?
@JustinPBarnett
@JustinPBarnett 2 года назад
Yes!
@linomatheus7418
@linomatheus7418 2 года назад
If you feel like your hands are rotating too slowly, remember to set the "rigidBody.MaxAngularVelocity" to a higher number. i believe default is 7.
@danielgarciagonzalez2391
@danielgarciagonzalez2391 3 года назад
Great video. So, second part :P?
@JustinPBarnett
@JustinPBarnett 3 года назад
It's coming!!
@olivername
@olivername Год назад
hey how do i stop hands going thought walls
@sheetanshus5179
@sheetanshus5179 3 года назад
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.
@JustinPBarnett
@JustinPBarnett 3 года назад
You can join the discord for some help if you need any!
@schaki05
@schaki05 3 года назад
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
@JustinPBarnett 3 года назад
Well I removed all the animation code in this video. You could just keep those in
@schaki05
@schaki05 3 года назад
@@JustinPBarnett Well I did. I did not delete anything from before. But the animation is gone anyways.
@JustinPBarnett
@JustinPBarnett 3 года назад
@@schaki05 you mean the animation file is gone?
@schaki05
@schaki05 3 года назад
@@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.
@schaki05
@schaki05 3 года назад
@@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 :)
@CSHorseBobJoe
@CSHorseBobJoe 2 года назад
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.
@hugoventer5856
@hugoventer5856 Год назад
How did you fix this issue?
@olivername
@olivername Год назад
hi will coilder stop them going thought objects walls without the other code
@JustinPBarnett
@JustinPBarnett Год назад
Yes, but the code is to keep the collider aligned on the player.
@westparezal
@westparezal 3 года назад
why you just don`t use XR Direct Interactor for Physics?)
@JustinPBarnett
@JustinPBarnett 2 года назад
Because it's not physics based
@jack8750
@jack8750 3 года назад
Looking forward to the next part, great stuff!
@JustinPBarnett
@JustinPBarnett 3 года назад
Thanks!!
@HienNguyen-jk4no
@HienNguyen-jk4no 3 года назад
how did you do it can you share with me , thank you
@JustinPBarnett
@JustinPBarnett 2 года назад
That's a vauge question
@rylandwilson739
@rylandwilson739 2 года назад
Instead of moving with the controller positions, my hands just fly away. Any solution to this?
@JustinPBarnett
@JustinPBarnett 2 года назад
Try teleporting them to the controllers' positions on start. You may be starting out touching another collider and that causes the flying away thing
@rylandwilson739
@rylandwilson739 2 года назад
@@JustinPBarnett I will try that, thank you
@Tu-madre6969
@Tu-madre6969 2 года назад
Did you manage to find a solution, I've the same problem
@rylandwilson739
@rylandwilson739 2 года назад
@@Tu-madre6969 I never was able to solve it, no
@Tu-madre6969
@Tu-madre6969 2 года назад
@@rylandwilson739 ok
@_Garm_
@_Garm_ 3 года назад
for curiosity, would it still work if i just added the collisions but , keeping the normal Xr control of the hands ?
@JustinPBarnett
@JustinPBarnett 3 года назад
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
@_Garm_
@_Garm_ 3 года назад
@@JustinPBarnett thank you :D
@JustinPBarnett
@JustinPBarnett 3 года назад
@@_Garm_ sure thing! it's fun to try and see everything shoot off in different directions lol
@_Garm_
@_Garm_ 3 года назад
@@JustinPBarnett haha could be game idea just there ,the "Hot potato game" :P
@JustinPBarnett
@JustinPBarnett 3 года назад
hahaha for real
@mg1632
@mg1632 3 года назад
Why not have each hand just have a mesh collider so you don't have to do each part of the hand?
@JustinPBarnett
@JustinPBarnett 3 года назад
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
@Tecfixdirect
@Tecfixdirect 3 года назад
anyone willing to discord and help me on screenshare, i have nearly it just struggle with the animation. is there no way to just import it :(
@JustinPBarnett
@JustinPBarnett 2 года назад
Yea ask around on the discord!
@stail2394
@stail2394 3 года назад
Is there a way to like skip over the animation part?
@JustinPBarnett
@JustinPBarnett 3 года назад
You mean like comment it out?
@DiegoSanchez-ly4xo
@DiegoSanchez-ly4xo 2 года назад
@@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
@rattlegoat
@rattlegoat 3 года назад
anyone else having issues not being able to move after this tutorial? the hands move, but only about .01 units before stopping. any help?
@praxtron
@praxtron 3 года назад
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
@JustinPBarnett
@JustinPBarnett 2 года назад
👆
@ATiredArchivist
@ATiredArchivist 3 года назад
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
@ATiredArchivist 3 года назад
also, side problem, my animations arnt running anymore, cant figure out why, seeing as the animator still has the controller and avatar set
@basvm6123
@basvm6123 3 года назад
@@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
@JustinPBarnett
@JustinPBarnett 2 года назад
Join the discord if you're still having issues and we can help you troubleshoot!
@arfiandi3998
@arfiandi3998 2 года назад
I have problem,my hands are shaking a little everytime
@JustinPBarnett
@JustinPBarnett 2 года назад
Check out the video coming out today about gorilla tag movement. It should help clear some stuff up.
@NULL3D
@NULL3D 2 года назад
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.
@JustinPBarnett
@JustinPBarnett 2 года назад
I'll add it to my queue!
@ErnestoConfused
@ErnestoConfused 3 года назад
just commenting for the algo. Thanks, m8!
@JustinPBarnett
@JustinPBarnett 2 года назад
Thanks so much!
@somerandomguy2892
@somerandomguy2892 3 года назад
the most important part of any vr game is to have a Rigidbody controller with NO Translate, No Transform, only AddForce or .Velocity.
@JustinPBarnett
@JustinPBarnett 3 года назад
Agreed for any physics-based game!
Далее
How to Setup VR Hands for the Best Experience
23:32
Просмотров 33 тыс.
ОТПРАВЬ СВОЕЙ ЛП/ЛД
00:10
Просмотров 134 тыс.
Cole Palmer Revenge vs Man City 🥶
00:20
Просмотров 1,1 млн
Building a Hand Poser for Unity XR
16:01
Просмотров 23 тыс.
Realistic Gun in VR - Part 1
9:54
Просмотров 55 тыс.
Mastering VR Hand Animation: Step by Step
28:03
Просмотров 109 тыс.
2023 Unity VR Basics - XR Hands
9:54
Просмотров 22 тыс.
MAKE A MAZE IN UNITY
30:51
Просмотров 18 тыс.