How to Grab Objects and Two Handed Grab in VR - Intermediate Unity VR Tutorial

Sdílet
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!

Komentáře • 120

  • @featherless656
    @featherless656 Před 2 lety +15

    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

  • @ProdigiaGames
    @ProdigiaGames Před 3 lety +7

    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!

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +1

      Thanks so much! I’ve definitely learned over the past several videos 😅

  • @skyreep1
    @skyreep1 Před 3 lety +4

    Can't wait for the next part in this series! They've been super helpful

  • @jonathanhobson7534
    @jonathanhobson7534 Před 3 lety +2

    Thank you so much! Looking forward to the next one!

  • @JustinPBarnett
    @JustinPBarnett  Před 3 lety +5

    Download the Project (for FREE): www.vrcreators.io/codedownloads

  • @jsivonenVR
    @jsivonenVR Před 3 lety +2

    Excellent points! 🙌🏻

  • @immortalhamster1645
    @immortalhamster1645 Před 3 lety +6

    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

  • @livingagoodlife4344
    @livingagoodlife4344 Před 3 lety +11

    Well. that when well!! only 24 errors, it's going to be a long night. lol!

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +4

      Oh no! Debugging is the worst. Definitely join the discord if you want some help!

    • @mr.mysteriousyt6118
      @mr.mysteriousyt6118 Před 3 lety +1

      Shouldn't be a problem if you understand the code, it just takes a long time

  • @tjeub
    @tjeub Před 3 lety +8

    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!

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +5

      Cool idea! Yea I'll look into what's involved with that and add it to my list!

  • @michaelemerson570
    @michaelemerson570 Před 2 lety

    Thanks for all your helpful tutorials! Just subscribed to you on Patreon :)

  • @Xzarations
    @Xzarations Před 3 lety +2

    Im a little late but still hyped for some quality grabbing content

    • @Xzarations
      @Xzarations Před 3 lety +1

      Also I’ve been craving to learn how procedural grabbing works and I can’t wait for that tutorial

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +2

      Coming soon!!

  • @benferguson223
    @benferguson223 Před 3 lety +1

    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!

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +4

      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

    • @benferguson223
      @benferguson223 Před 3 lety +1

      @@JustinPBarnett LEGEND!

  • @Malekdu13012
    @Malekdu13012 Před 2 lety +2

    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 !

  • @azataiabylbek5262
    @azataiabylbek5262 Před 2 lety

    Good job~

  • @darrencook5073
    @darrencook5073 Před 3 lety +3

    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?

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +2

      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

  • @lint_animations4372
    @lint_animations4372 Před 3 lety +2

    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!

  • @ketabtasviri3291
    @ketabtasviri3291 Před rokem

    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?

  • @brandonhalvorsen2185
    @brandonhalvorsen2185 Před 2 lety +1

    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?

  • @HaniSharif
    @HaniSharif Před 3 lety +1

    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??

  • @Linkatrazz
    @Linkatrazz Před rokem +2

    Can you make a tutorial with this hand script on how to add climbing

  • @kenzielaing4112
    @kenzielaing4112 Před 2 lety +2

    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.

  • @TB3hnz
    @TB3hnz Před 2 lety

    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?

  • @SimpleDays101
    @SimpleDays101 Před 2 lety

    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?

  • @Z-AXIS_Dev
    @Z-AXIS_Dev Před 6 měsíci

    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 😊

  • @BobRoss-uq2wu
    @BobRoss-uq2wu Před 3 lety +1

    I am very much looking forward to a procedural grip tutorial, been trying to wrap my head around it for a while 😂

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety +2

      Coming soon (hopefully 😅)!

    • @MoldySugar2205
      @MoldySugar2205 Před 2 lety +1

      @@JustinPBarnett Insanely complicated ain't it

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      @@MoldySugar2205 at this point it’s more of a motivation issue 😅

    • @sdhority
      @sdhority Před 2 lety +1

      @@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!

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety +1

      @@sdhority wow thanks so much!! That’s super encouraging

  • @qualar
    @qualar Před 2 lety

    After watching one of your other videos I purchased Auto Hands. Could that be used instead of the method here?

  • @titanstudios6722
    @titanstudios6722 Před 2 lety +1

    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.

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      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

  • @ij20man35
    @ij20man35 Před rokem

    19:06 - In Visual Studio ALT+CTRL will extend your cursor.

  • @lukasstryg3688
    @lukasstryg3688 Před 2 lety +1

    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?😃

  • @VonchkynProduction
    @VonchkynProduction Před 2 lety +2

    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 :'(

  • @goodknight3659
    @goodknight3659 Před 3 lety +2

    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.

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +1

      Did you adjust the offsets to line up with your controllers' positions?

    • @goodknight3659
      @goodknight3659 Před 3 lety +1

      @@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!

    • @goodknight3659
      @goodknight3659 Před 3 lety +1

      @@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.

  • @Xionic420
    @Xionic420 Před rokem

    Can you do a grab tutorial for your gorilla tag movement?

  • @HellSpawnRulerOfHell
    @HellSpawnRulerOfHell Před 3 lety +3

    Is there anything that works like the SteamVR Unity plugin for OpenXR?

  • @NAGYT101
    @NAGYT101 Před rokem +1

    if you want a heavy object rise the value of the mass
    Edit: for those who wonder what mass the mass in the rigidbody

  • @kje081697
    @kje081697 Před 3 lety +5

    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?

    • @MickNix
      @MickNix Před 3 lety +2

      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

    • @gravity_mxk5663
      @gravity_mxk5663 Před 2 lety +1

      I’m having the same problem, did you ever figure it out???

    • @gravity_mxk5663
      @gravity_mxk5663 Před 2 lety +1

      @@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!

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety +1

      Yea I wasn't super clear adding the using statements. Sorry!

    • @solbassett-albert5587
      @solbassett-albert5587 Před rokem +2

      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

  • @fused6767
    @fused6767 Před 3 lety +3

    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

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +6

      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

    • @fused6767
      @fused6767 Před 3 lety +2

      @@JustinPBarnett Thank you a lot! - I'll try to look into it. Looking forward to your next video!

  • @callumbloys2000
    @callumbloys2000 Před 2 lety +1

    Now ive got to this point how do we then implement the hand animations back in

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      Add back in the scripts that we took out. You may need to modify them a bit now

  • @diljotthunder4348
    @diljotthunder4348 Před 10 měsíci

    What video is the one that poses the hand to the object I don’t know where it is

    • @JustinPBarnett
      @JustinPBarnett  Před 10 měsíci

      I don't have one of those up yet, but you can look up "procedural vr hand tutorial" to probably get the best results.

  • @daniell.7130
    @daniell.7130 Před 2 lety

    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!

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      If you're still having issues join the Discord and we can help you troubleshoot in #dev-help!

  • @catthatrat853
    @catthatrat853 Před 3 lety +1

    How would I go about making the hands invisible on grab?

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +1

      You can toggle the gameobject.mesh to be enabled or not

  • @Sticks_Dev
    @Sticks_Dev Před 2 lety +1

    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.

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      Haven't made it yet! 😅 Been slacking on that video

  • @Justfillintheblank
    @Justfillintheblank Před 3 lety +1

    Grabbing..but what about climbing? Could I use these methods to climb in VR?

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      Yes! Check out my gorilla tag video. You can adapt that for climbing

  • @talbertherndon1925
    @talbertherndon1925 Před 2 lety +1

    Question will this work with a OVR Player Controller?

  • @allenng5896
    @allenng5896 Před 8 měsíci

    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?

  • @wtpro1012
    @wtpro1012 Před 2 lety +2

    Did a continuation of this video come out?

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      Not yet unfortunately 😬 I've been slacking...

    • @wtpro1012
      @wtpro1012 Před 2 lety +1

      @@JustinPBarnett Are you planning in releasing one? Would be awesome!

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety +1

      @@wtpro1012 Yes! Within the next month-ish hopefully!

  • @thejaplong
    @thejaplong Před 3 lety +1

    and where is the link to the wrench ??

  • @MoldySugar2205
    @MoldySugar2205 Před 2 lety +2

    Will the animating work with this?

  • @mrmagit5239
    @mrmagit5239 Před 3 lety +1

    Could I do this to a full body?

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +1

      You mean like the physics, or do an inverse kinematics kind of thing?

    • @mrmagit5239
      @mrmagit5239 Před 3 lety +1

      @@JustinPBarnett yeah

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +1

      @@mrmagit5239 Check out this video! czcams.com/video/MYOjQICbd8I/video.html

    • @mrmagit5239
      @mrmagit5239 Před 3 lety +1

      @@JustinPBarnett ok will do!

  • @Updog97
    @Updog97 Před 3 lety +1

    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?

    • @JustinPBarnett
      @JustinPBarnett  Před 3 lety +2

      Join our discord and I'm sure someone can help you troubleshoot!

    • @zotzilaha4777
      @zotzilaha4777 Před 3 lety +4

      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.

    • @pineapplecatcone2894
      @pineapplecatcone2894 Před 3 lety

      @@zotzilaha4777 This fixed it for me, thanks!

  • @nikileshtm
    @nikileshtm Před 2 lety +1

    I'm having a weird problem that the hands turn weirdly

    • @JustinPBarnett
      @JustinPBarnett  Před 2 lety

      Join the Discord and we can help you troubleshoot!