XR Grab Interactables in Unity XR Interaction Toolkit

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so in this tutorial we're going to set up an XR grab interactable um in the last one in this playlist we made a simple button using a simple interactable and when we press the button it turned red and it made a sphere appear now we're going to make that sphere into a ball we can pick up and throw so if we click on the sphere object and do add component we're going to look for XR grab and there are a couple of things called grab so we're looking for XR grab interactable and if we apply that to the Sphere not only do we get the grab interactable component but it comes with a required rigid body so this sphere is going to be subject to gravity in physics so that means before we do anything else when we hit play um and then take control of our left controller and point it at our button not only did we generate a sphere but the sphere fell to the table because it's subject to gravity so that's something we might want to make changes to but we'll get there um so we're going to now take a look at the XR grab interactable component it has a lot of the same defaults as the simple interactable but once we get down to about here things start to change so the movement type is relatively important in grab interactables there are three choices instantaneous kinematic or velocity tracking and in that order they're sort of increasingly subject to physics so instantaneous just basically attaches the object to your controller and you can wave it around and it's suddenly like capable of passing through colliders like it will you could wave it around and pass it right through the uh the table it's sitting on kinematic means that it's going to collide with other things that have rigid bodies for example if we add a rigid body to our cylinder um it should bump into our cylinder but not our Cube because our Cube doesn't have a a rigid body but our cylinder does then finally velocity tracking um will collide with everything um so this is perhaps the most um realistic or physics respecting of these um of these movement methods but sometimes you don't want that like you know I can't go through the table or I can't go through the ground or whatever and uh maybe that's fine in your game but if this thing's supposed to be treated like um you know a power up or some kind of inventory object or something like that it could potentially start banging into like your body or other colliders that you don't want it to bang into so um so you want to Choose Wisely which uh Which movement type you want um the only other settings here that I think are uh worth pointing out are the rest of it essentially deals with the um the movement and throwing of this object it can track the position of the object and it can choose to smooth that position or not if you're finding that the movement while you're holding it in your hand looks really jumpy you could choose smooth position smooth rotation will attempt to smooth as the thing rotates and not just moves throw on detaches set by default I think that's what most people would want if you grab an object when we let go of it it should probably fall out in a way that seems a little bit thrown if that's not appropriate for what you're building you can turn it off here you can also increase the um the velocity scale of the throw here and I think this is a pretty important slider because when we have an expensive fragile XR controller in our hand we are unlikely to throw as hard as we would throw in the real world but we'll also be very disappointed by how wimpy the throw comes out so this is like a multiplier that makes your throw a little more super powered and you just want to land where it feels right you know that like the amount of throwing you're comfortable with leads to the amount of velocity that you wish it did so this isn't exactly about representing reality it's sort of about giving people the right amount of super powered throws so that they feel like it's realistic and not not artificially underpowered so it starts at 1.5 and you can turn it up from there um so one trick that I want to show you is you might remember when we first built this object it was just kind of hovering above our tables like like the cube is but now that it has a rigid body it falls to the table when it spawns um and I might not want that I might want it to start hovering so an easy way to do that is in the rigid body to set it is kinematic so that means it's subject uh you know to physics without the force of gravity just dropping it straight down at um at spawn but that solves one problem and creates another um so we make our sphere it doesn't fall we grab it by pointing at it with our Ray interactor and either using the grab button or the G key in our device simulator and so I've got it but now when I let go of it it doesn't throw or fall or anything it's just remains kinematic it's a floating object um so um I want to have my cake and eat it too I want to be able to grab the thing and drop or throw it but um only after picking it up the first time so that way I'm going to use an interactable event to make this change so we're going to set it kinematic so that it floats at the start but then so I'm going to use the select exit um function or event rather and the idea there is that select is is referring to the grab button so when we let go of the grab button we exit select then is the moment we want kinematic to be turned off so I'm going to add an object here it'll be the sphere and I'm going to give it a function we're going to address the rigid body and look for something related to kinematic here we go Bool is kinematic so that's looking for a Boolean that that is an on or off tick box setting whether the thing is kinematic or not um so we're going to have that be off so now we'll give it a test and kinematic now we grab it with the G and when I let go of it it's not kinematic anymore and it's subject to gravity and if we were to attempt to throw it not super easy with the device simulator but it's possible
Info
Channel: Ryan Murray
Views: 4,870
Rating: undefined out of 5
Keywords:
Id: -QngemQx9NY
Channel Id: undefined
Length: 8min 19sec (499 seconds)
Published: Tue May 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.