How to Grab Objects and Two Handed Grab in VR - Intermediate Unity VR Tutorial
Vložit
- čas přidán 7. 07. 2024
- When you're in VR, you pick up a gun or object and it feels so clunky because your hand reacts only if it's on top of something, but then gravity pulls at it. Gosh, I hate getting hung up by physics, right?! Well, not any more friends...
Hey guys! In this video, you'll learn how to pick up objects using physics. The cool part is that this script we'll write also allows for built-in two-handed grabbing! Try it out and let me know what you think in the comments below 👇
📺 Watch Next: • What Do I Need to Beco...
🥽 Enroll in the (now FREE) VR Creator Academy: skool.com/vrcreatoracademy
⌚ Timestamps
0:00 Like the video!
1:17 Setup
3:47 Update the Existing Code
5:43 Add Variables
8:27 Add to the Start Method
9:20 Add New Grab Method
12:56 Add New GrabObject Method
20:00 Add New Release Method
21:35 Testing & Debugging
26:08 Subscribe!
This guy is great, all of his tutorials are compatible with the old and new stuff, the reason I found this guy is because I was looking for someone who wouldn’t have complicated ways of doing things when it comes to vr
Wow thanks so much!!
Always great insights! Nice attention to detail too, making sure the face cam was not obscuring anything important...definitely my first go-to whenever looking for VR dev content!
Thanks so much! I’ve definitely learned over the past several videos 😅
Can't wait for the next part in this series! They've been super helpful
Glad to hear it!
Thank you so much! Looking forward to the next one!
You're so welcome!
Download the Project (for FREE): www.vrcreators.io/codedownloads
where
This video broke all my process :'(
Excellent points! 🙌🏻
Thanks!
I’m super excited to do this tutorial, I’ve been making an FPS game with the interaction toolkits default grabbing and I tried to follow a valem tutorial for the two hand grab, but it was already outdated and didn’t work. This seems way way better
Glad I could help!
Well. that when well!! only 24 errors, it's going to be a long night. lol!
Oh no! Debugging is the worst. Definitely join the discord if you want some help!
Shouldn't be a problem if you understand the code, it just takes a long time
Hey Justin, awesome video! It would be cool if you made a video about controlling a miniature environment with these hands. So pan and zoom around a miniature environment with objects in them. Something like the curious tale of the stolen pets. Keep up the work!
Cool idea! Yea I'll look into what's involved with that and add it to my list!
Thanks for all your helpful tutorials! Just subscribed to you on Patreon :)
Really appreciate that!!
Im a little late but still hyped for some quality grabbing content
Also I’ve been craving to learn how procedural grabbing works and I can’t wait for that tutorial
Coming soon!!
Hey justin, love your videos, really well done. I am working on a game at the moment and I would love a tutorial to create zero gravity similar to echo vr. Using push and pull to move the player around space while floating. cheers for your content, keep it up!
Yes!! I want to make a space game (next game maybe? 😏) and will definitely figure out how to do that mechanic and do a tutorial about it
@@JustinPBarnett LEGEND!
Hello, i've been following your videos for a school project and they've been really helpful ! Do you plan on doing the procedural grip anytime soon ? Thanks a lot !
That's the plan! Best of luck on your projects
Good job~
Thanks!
First of all, thank you so much for this content. I am looking forward to your dev log on the new game.
I have a project where I am not using the XR Interactions Toolkit, only XR Plugin Management with a camera converted to an XR Rig. I have a very simple hand setup and, when the player touches a particular sphere in the scene, I am trying to make the hand move across the surface of the sphere. However, I am having a lot of difficulty with this. For the most part, it is because the primitive that I am using for the hand moves through the sphere, or conversely, when I do get any physics working, the primitive for the hand seems to spin away from the sphere and fall into an odd state. Would you have any tips for starting on something like this? For example, what would your basic settings for the colliders be in this case? Or do you think I should prevent the movement of the hand within the boundary of the sphere via code?
Try checking out my physics-based hands tutorial and see if that helps. My idea would be to use physics on the sphere and hands to prevent any pass-through. You can't just add a rigidbody to your XR controller and expect it to work though. There's a lot more that's involved
Have you ever thought about making videos on how to make a specific vr game like a fps or a walkabout world ect ,i think it might help people really grasp vr development and i think you would be really good at it!
Absolutely!
Thank you very much for your excellent education
I wanted it to be red when we hold the cube with the right hand and blue when we hold the same cube with the left hand.
How should I do?
I'm trying to think of a way to force a specific orientation for certain objects, like tools or weapons. Maybe a second grabbable layer with a grabpoint already defined?
Yea a grab point would be a good way to do that!
Thank you so much! You are awesome. Also if I need to fold the hand when i pick something up, what way do you suggest that i use??
You could do an animation or procedural grip!
Can you make a tutorial with this hand script on how to add climbing
Check out my Gorilla Tag livestream!
I wonder if I can use this tutorial for the 3D modelling function I’m hoping to replicate. Which would allow the model to grab their clothing in vr. Such as grabbing a skirt to curtsy. It’s really cool but models with it are about $100+ and I just want to learn the function. It was interesting how a hand gesture would allow the cloth to be held.
As long as the cloth is physics-based, then yes!
Hey Justin! How do you store multiple executables in your Quest 2? I have only one saved in my Quest 2, but when I made both physics and non-physics versions of my hands, and every time I build to the Oculus, each build just overrides that executable in my Oculus. I want to be able to save both versions into my Oculus, and to build so that, say, my non-physics hands won't override my physics hands.
Does that make sense?
So I've got an issue I can't seem to solve: I've created some daggers and put the grabbable script on them, then added an attach point for them and it works fine overall, but If I drop the daggers 2-3 times, the objects start to drift away from where I've set the attach point. I can't find anything about this online. Think you might have some insight on this?
Bro please teach us the procedural grip I really need it for my project and I can't find any source except for the ones that sell that and it can be hard for someone like me to buy them I love your content btw 😊
I am very much looking forward to a procedural grip tutorial, been trying to wrap my head around it for a while 😂
Coming soon (hopefully 😅)!
@@JustinPBarnett Insanely complicated ain't it
@@MoldySugar2205 at this point it’s more of a motivation issue 😅
@@JustinPBarnett keep at it man, we're all so very grateful for the fantastic content you put together! Personally I'm really excited for your take on procedural grabbing, you have a great way of explaining concepts that has helped me significantly while self learning game development. Cheers mate!
@@sdhority wow thanks so much!! That’s super encouraging
After watching one of your other videos I purchased Auto Hands. Could that be used instead of the method here?
Great video, the only problem. that I'm having is sometimes something will go wrong, and the cube or the wrench will get "stuck" on the hand, and when I try to grab it with the other hand, it freaks out and starts having a seizure.
Check out my latest Gorilla Tag livestream video. Towards the end I implement a better grabbing mechanic that doesn't stick. I used it for grabbing the walls, but the same thing applies to objects
19:06 - In Visual Studio ALT+CTRL will extend your cursor.
I'm currently working on a VR Game Exams project that ends on February 25th. Would you be able to make the procedural grip tutorial before then or should I just implement animations instead?😃
We'll see 😅
Hi, thanks for the detailed video, really appreciate it. I was just wondering if you could do a tutorial on weapons that require 2 hands, like a rifle or a machine gun. There are tutorials on youtube, but they all use the old unity input system so it's not that helpful :'(
Yea that's on my list!
@@JustinPBarnett Nice! Really Looking forward to it!
Thanks so much for the videos justin! For some odd reason my hands are not lining up with my controllers. I thought i followed everything to a tee but I guess i fucked up somewhere. Not really sure where to go from here lmao, picking up works just fine if i get lucky enough to angle them correctly. Also if i run into a wall and continue to run my hands will just keep floating in that same direction.
Did you adjust the offsets to line up with your controllers' positions?
@@JustinPBarnett Thanks so much for the reply, I ended up fixing my hands being lined up! But the issue still remains when i run into a wall my hands will keep flying forward infront of me. Just got the patreon and love your work man! Thank ya!
@@JustinPBarnett Now that i look at it, I'm seeing that any kind of change in speed will move my hands a bit out of position. If i jump off map my hands start flying up further and further away. It looks like its trying to keep up with the controllers but it can't catch up.
Can you do a grab tutorial for your gorilla tag movement?
Is there anything that works like the SteamVR Unity plugin for OpenXR?
Not yet unfortunately 😒
if you want a heavy object rise the value of the mass
Edit: for those who wonder what mass the mass in the rigidbody
Precisely
Hey Justin great video! I have i quick question tho, for some reason my console is giving me an error saying : The type or namespace name 'InputAction' could not be found (are you missing a directive or assembly reference?). Do you have any suggestions on how to fix this?
I actually found out what was wrong, if you look at the top of his scrip you will see a 'using' that you don’t have
I’m having the same problem, did you ever figure it out???
@@MickNix I have all of the using things, but it is still not working….
Edit: NVM you were right! He sneaky added them at the end so I miss em. Thanks!
Yea I wasn't super clear adding the using statements. Sorry!
For anyone wanting to know whta the using statement was it was (using UnityEngine.InputSystem;) took me a while to figure out hope it helps others
How did you get into C#? I'm learning Java and Python in school, but I would like to learn C# aswell. Any recommendations for a place to start?
Love your content between. Keep it up!
- Cheers from Denmark
Both my parents are software developers, so I kinda grew up with that mindset. I learned how to code from a few textbooks and college (well...I learned FOR college FROM CZcams videos lol). I'd highly recommend Brackey's C# videos. Here's the playlist: czcams.com/video/N775KsWQVkw/video.html
@@JustinPBarnett Thank you a lot! - I'll try to look into it. Looking forward to your next video!
Now ive got to this point how do we then implement the hand animations back in
Add back in the scripts that we took out. You may need to modify them a bit now
What video is the one that poses the hand to the object I don’t know where it is
I don't have one of those up yet, but you can look up "procedural vr hand tutorial" to probably get the best results.
Hello Justin, I have followed the steps in all three of these videos so far, but when I test the unity game, the hands are just stuck in their original positions vibrating really fast. Do you have any suggestions? Thanks!
If you're still having issues join the Discord and we can help you troubleshoot in #dev-help!
How would I go about making the hands invisible on grab?
You can toggle the gameobject.mesh to be enabled or not
I was just searching across your channel for the next part of this series, you said it had procedural grabbing with the fingers properly matching the object but I can't find it? Am I just really stupid? I swear I've seen it before like a month ago.
Haven't made it yet! 😅 Been slacking on that video
Grabbing..but what about climbing? Could I use these methods to climb in VR?
Yes! Check out my gorilla tag video. You can adapt that for climbing
Question will this work with a OVR Player Controller?
You can't mix openXR and OVR
When i try to grab the same object with both hands, it glitches out and gets stuck on one hand. Anyone else faced this issue?
Did a continuation of this video come out?
Not yet unfortunately 😬 I've been slacking...
@@JustinPBarnett Are you planning in releasing one? Would be awesome!
@@wtpro1012 Yes! Within the next month-ish hopefully!
and where is the link to the wrench ??
Just search 'wrench' in the unity asset store
Will the animating work with this?
Might need some tweaks, but yea it should!
@@JustinPBarnett sick
Could I do this to a full body?
You mean like the physics, or do an inverse kinematics kind of thing?
@@JustinPBarnett yeah
@@mrmagit5239 Check out this video! czcams.com/video/MYOjQICbd8I/video.html
@@JustinPBarnett ok will do!
I am having an issue:
The fixed joint (_joint2) component on my hand gameobject isn't always destroyed when I release an object. This causes the object to be stuck on my hand. Sometimes when try I grabbing and dropping the stuck object repeatedly, there ends up being multiple fixed joint components on the hand gameobject.
I am also getting this error:
NullReferenceException: Object reference not set to an instance of an object
Hand+d__20.MoveNext () (at Assets/Scripts/Hand.cs:162)
Any idea how to fix this issue?
Join our discord and I'm sure someone can help you troubleshoot!
change your join distance to a larger value, i set mine to 0.9 and this should fix it. the problem is when the colliders in your hands go through the mesh you are holding.
@@zotzilaha4777 This fixed it for me, thanks!
I'm having a weird problem that the hands turn weirdly
Join the Discord and we can help you troubleshoot!