2023 Unity VR Basics - Grabbing Objects
Summary
TLDRThis video tutorial delves into the mechanics of object grabbing in virtual reality (VR) using Unity's XR Interaction Toolkit. It covers the essentials of setting up XR Direct Interactors on VR controllers and configuring them with colliders for interaction. The video also explains how to create XR Grab Interactables for objects, ensuring they have the necessary Rigidbody and collider components. Further, it explores various interaction modes, movement types, and the use of Attach Transforms for precise object handling. The tutorial concludes with a discussion on interactable events, including audio and haptic feedback, to enhance user immersion in VR experiences.
Takeaways
- 🎯 To grab objects in VR, utilize the XR Grab Interactable and XR Direct Interactor components.
- 📦 Adding an XR Direct Interactor to a controller requires a collider, such as a Sphere Collider set to 'Is Trigger' for functionality.
- 🔍 The Interaction Manager handles the interaction between the interactor (hand) and interactables (grabbable objects).
- 🎭 The Interaction Layer Mask allows for selective interaction, separating UI components from grabbable objects.
- 🖐️ Select Action Trigger determines how selection starts, with options like 'States Change', 'State', 'Toggle', and 'Sticky'.
- 👀 Hide Controller on Select can be used to improve visual aesthetics during object interaction.
- 🔨 XR Grab Interactables require a Rigidbody and a collider to function properly.
- 📏 Collision Detection can be set to 'Continuous Dynamic' to prevent objects from passing through the ground at high speeds.
- 🔄 Movement Types for grab interactables include Kinematic, Instantaneous, and Velocity Tracking, each with different behaviors.
- 🎚 Attach Transform allows for precise control over where and how objects attach to the hand during interaction.
Q & A
What are the two components required for grabbing objects in VR as discussed in the script?
-The two components required for grabbing objects in VR are the XR Grab Interactable and the XR Direct Interactor.
Why is a collider necessary for the XR Direct Interactor to function?
-A collider, specifically set as a trigger, is necessary for the XR Direct Interactor to function because it acts as a trigger for interaction, allowing the VR system to detect when the user's hand is near an object that can be grabbed.
What is the purpose of the Interaction Manager within the XR Direct Interactor?
-The Interaction Manager within the XR Direct Interactor is responsible for handling the interaction between the interactor (the user's hand) and the interactable objects that can be picked up.
How does the Interaction Layer Mask in the XR Direct Interactor work?
-The Interaction Layer Mask in the XR Direct Interactor allows the developer to specify which layers the interactor should interact with. This can be used to separate interactions, such as only allowing UI components to interact with other UI elements and not with the grabbable objects.
What are the different select action triggers available in the XR Direct Interactor?
-The different select action triggers available in the XR Direct Interactor are States Change, State, Toggle, and Sticky. Each offers a different method of how the selection and grabbing of objects are initiated and maintained.
Why might someone choose to hide the controller on select?
-Hiding the controller on select is chosen to improve the visual realism of the VR experience, as it prevents the user's hand model from visibly passing through objects during interaction, which can be visually jarring.
What is an XR Grab Interactable and why is it necessary for grabbing objects in VR?
-An XR Grab Interactable is a component that must be added to objects in the VR scene to make them grabbable. It is necessary because it allows the XR system to recognize these objects as interactable and respond to the user's grabbing actions.
Why does the XR Grab Interactable require a Rigidbody component?
-The XR Grab Interactable requires a Rigidbody component because it allows the object to have physical properties that can be manipulated by the user, such as mass and the ability to interact with other objects through collisions.
What are the different movement types available for XR Grab Interactables?
-The different movement types available for XR Grab Interactables are Kinematic, Instantaneous, and Velocity Tracking. Each type affects how the object moves and interacts with the user's hand and other objects in the VR environment.
How does the Attach Transform feature work in the XR Grab Interactable?
-The Attach Transform feature in the XR Grab Interactable allows the developer to specify an exact point on the object where it should attach to the user's hand when grabbed. This ensures that the object's orientation and position are correct relative to the hand.
What are Interactable Events and how can they be used in VR development?
-Interactable Events are triggers that occur when the interactor comes into contact with an interactable object, such as hovering over it or selecting it. They can be used to create interactive feedback, like changing the object's appearance or activating abilities, to enhance the user's experience.
Outlines
🤲 Introduction to VR Object Grabbing
The video begins with an introduction to grabbing objects in virtual reality (VR), focusing on the use of two key components: the XR Grab Interactable and the XR Direct Interactor. The presenter aims to cover the topic efficiently and starts by setting up the project with the XR origin and hand controllers. The XR Direct Interactor is added to the controllers, and it's explained that a collider, specifically a sphere collider set to trigger, is necessary for the interactor to function. The presenter adjusts the collider's size for a more accurate hand interaction, and the process is repeated for the left hand. The video then delves into the components of the XR Direct Interactor, such as the interaction manager, interaction layer mask, and different select action triggers like state changes, state, toggle, and sticky. The presenter also discusses the option to hide the controller on select and the starting selected interactable feature, which allows objects to be pre-grasped at the scene's start.
🔨 Setting Up Grab Interactables
The second paragraph continues the tutorial by demonstrating how to create grabbable objects in VR. The presenter adds a 3D cube to the scene and attaches an XR Grab Interactable component to it, emphasizing that a Rigidbody is mandatory for the component to work. The Rigidbody's collision detection is set to 'Continuous Dynamic' to prevent objects from passing through the ground at high speeds. The presenter then adjusts the interaction layer mask to ensure the grab interactable only interacts with the correct layer. Various select modes are introduced, with a focus on the single select mode for this tutorial. The gaze configuration is mentioned but not covered due to the lack of eye-tracking hardware. The presenter also discusses movement types, such as kinematic, instantaneous, and velocity tracking, and their effects on object interaction. The concept of an attach transform is introduced, which allows for precise control over where and how objects attach to the hand controller in VR.
🎮 Interactable Events and Conclusion
In the final paragraph, the presenter explores interactable events, which are triggered when the interactor comes into contact with an interactable object, such as hovering or selecting it. These events can be used to create visual cues for the player, like changing the object's mesh when it's hover over. The presenter also touches on the audio and haptic events available in the XR Direct Interactor, which can enhance immersion by providing auditory and tactile feedback when objects are interacted with. The tutorial concludes with a reminder to support the content creator, either through Patreon or simply by liking the video, and a tease for future content that will perfect the throwing mechanics in VR.
Mindmap
Keywords
💡XR Grab Interactable
💡XR Direct Interactor
💡Collider
💡Interaction Manager
💡Interaction Layer Mask
💡Select Action Trigger
💡Hide Controller on Select
💡Starting Selected Interactable
💡Attach Transform
💡Interactable Events
Highlights
Introduction to grabbing objects in VR using XR Grab Interactable and XR Direct Interactor components.
Adding XR Direct Interactor to the controllers with a sphere collider set as a trigger.
Adjusting the collider size for a more precise interaction with objects.
Setting up the Interaction Manager and Interaction Layer Mask for object interaction.
Explanation of different select action triggers like States Change, State, Toggle, and Sticky.
Option to hide the controller on select for a more realistic grabbing experience.
Creating grab interactables by adding the XR Grab Interactable component to objects.
Requirement of a Rigidbody and collider for XR Grab Interactables to function properly.
Setting the Collision Detection mode to Continuous Dynamic for more accurate interactions.
Configuring the Select Mode for single or multiple hand grabbing.
Discussing movement types like Kinematic, Instantaneous, and Velocity Tracking.
Creating an Attach Transform for precise object attachment to the hand.
Adjusting the Attach Transform's rotation to match the hand's orientation.
Using Interactable Events to trigger actions like changing mesh or activating items.
Incorporating Audio and Haptic Events to enhance user interaction and immersion.
Practical demonstration of grabbing objects in a VR scene with the configured settings.
Encouragement for Patreon support and appreciation for viewers.
Transcripts
let's talk about grabbing objects in VR
and in order to grab things we're going
to need to know how to use two
components that being the XR grab
interactable and the XR direct
interactor as always I want to cover as
much as possible in the smallest amount
of time so let's get started opening up
the project you'll see here I haven't
really added anything new I do have this
new object here that I'll go over later
in the video but yeah we have the XR
origin and then we have our left and
right hand controllers let's kick things
off by adding a XR direct interact to do
that all we have to do is Select our two
controllers here and I'm going to type
in XR direct interactor and there we go
we have the XR director interactor but
it's also going to need some form of
collider that's going to act as a
trigger without that this will not work
so I'm going to add a sphere collider
and expand this out I'm going to set it
to is trigger and then we have a pretty
big radius here so we need to reduce it
down and you know I'm just going to grab
the hand model for a reference let's see
where is my yeah let's go with the right
hand and I'll just drag this into the
scene make sure it's zeroed out
all right and so I'm going to take this
radius and reduce it I'm going to try
point one and you see that is just about
the right size you know you could try
something like
.08 if you want it to be a little more
exact for when your hand interacts with
an object and then we just have to make
sure that we do this for the left hand
as well yeah you know I like .08 a
little better and then I'm just going to
get rid of this reference so with that
let's go over the director interactor
looking through some of these components
you can see we have an interaction
manager so that is going to be handling
the interaction between our interactor
which is going to be our hand and then
the interactable which will be the
objects that we can pick up next we have
an interaction layer mask so we might
not want to interact with every single
object in the scene sometimes you want
your UI components to just interact with
UI components and so this is where we
would add a layer to separate these
interactions and you just click add
layer and we could add one here called
the interactable
coming back to our hands so you know I
could say uh I don't want this to
interact with anything I only want
things to interact with the interactable
layer and then down here we have an
attached transform so if you do not have
anything here and this is set to none
it's just going to use the transform of
the XR direct interactor which I'm okay
with right now we also have select
action trigger so this would determine
how our select starts so it's kind of
interesting so States change is how you
would expect you know you go down you
grab an object and then when you pick it
up you know you're holding the grip
button but when you release it it drops
the other ones we have is state so how
State works is when you go in and you
are holding the button even if you are
not interacting with the object if you
ran into it while holding the grip
button it would pick it up which is kind
of a weird interaction but there it is
we also have toggle and sticky and
toggle and sticky are very similar in
the sense that you would be hovering
over a object and when it's togg you can
press the grip button or whatever your
activation button is and then when you
release it it'll still stay on you but
when you press it again then it will
release and how sticky works is the same
way but it only lets go of the object
when you let go for this second time so
yeah there you go a few options on how
you can pick up your objects we also
have hide controller on select and you
know I'm going to select both my left
and right hand controller and I'm just
going to check that so if you don't have
a custom animation or dynamic grabbing
for your objects it kind of looks a
little wonky the hand will go right
through the object and personally I like
to hide the controller on select but you
know actually for demonstration purposes
later I'm going to check this off for
now we also have the odd choice right
here of starting selected interactable
so if we boot up the scene and head
something here if we had something that
was a XR grab interactable then this
would just start off in our hand at the
beginning of the scene so say you want
the player just to have a gun in their
hand at the beginning this is where you
could put that and finally we have a
bunch of events here audio events haptic
events in interactor events that we can
use when we pick up our objects but we
don't have any objects to pick up so
let's fix that now in order to grab
things we need grab interactables and
well just objects to grab them so I am
going to activate this and show you what
I've done here and as you can see I'm
actually going to hide these for now all
I have here is a table and the table is
just comprised of a cube that I made I
put a 0.5 position and scale of one and
yeah this is just a simple little table
so we can grab onto things and you'll
see the XR origin is right here so when
we start up the scene we'll be looking
at this table and be able to grab things
off it and well let's make a grab
interactable so to do that we need to
right click grab a 3D cube I am going to
reduce this to let's see 0.2 might be a
good size yeah just for now and there we
go next we need to add a well grab
interactable component to it so I'm
going to come over here add X our grab
interactable and one thing I want to
point out is you'll notice that it added
a rigid body right here XR grab
interactables will not work without a
rigid body you kind of like how our
hands will not work without a sphere
collider set to trigger or any collider
set to trigger we need to have a rigid
body on our XR grab interactables and
also some form of collider as well one
thing I'll point out about the rigid
body is you might want to up the
Collision detection so I'm going to set
this to continuous Dynamic and this is
going to be a little more expensive than
doing something like discrete or
continuous but it does help prevent
objects from flying through the ground
when they're going at higher speeds if
you're ever having those problems where
the colliders aren't really picking
things up you might want to consider
continuous Dynamic expanding this out
let's go over some things for the grab
interact you'll see here that it has the
interaction manager from before the one
that is responsible for handling our
interactions between our interactables
and interact doors we also have the
interaction layer mask and this is set
to default and if you remember just a
second ago I set this to only
interactable so we need to make sure
that this is set to the proper one so
I'm going to oh where is it there we go
and there we go I'm going to set it to
interactable take it off default we also
have different types of Select mode so
there is single and multiple just for
this one I'm just going to cover single
we'll cover multiple hand grabbing
objects later we have a gaze
configuration which well I can't afford
the Oculus Pro or any other eye tracking
device so I can't cover it sorry but hey
I do have a patreon if you want to help
me out with that patreon plug seriously
though just a like would be enough if
you're finding this video helpful but
yeah all right let's move on uh we also
have different movement types I will
cover this in a second we also can
determine if we want the object to track
or not so if we don't want it to track
let's say the position we could turn
that off here or if you want the rate
rotation of the object to be maintained
so even though we're turning our
controllers then if we turn this off it
wouldn't turn with it it just moves the
position we can also decide to smooth
this out and so this kind of gives you a
bit of a floaty feel that you can play
with same with the road rotation we also
have a ton of options when it comes to
throwing and so we can determine if we
want to throw on detach or just drop it
immediately and not track the velocity
and we can play with this later I'm
going to try to make a video that
perfects throwing because well for the
game Jam I made a game where you
primarily throw things and God did I
hate my throwing but right and then we
have attached transforms where we can
specifically say where I pick up an
object I want you to attach exactly at
this location and I will cover that in
just one second now I know I keep saying
one second and that one second has
passed so let's cover what the movement
types are so I'm going to go ahead and
click this off
and I'm going to activate these three
cubes and as you can see here there's
nothing crazy going on I've just put a
little canvas on these to symbolize what
these are going to stand for and so what
we have here is a cube with kinematic
instantaneous and velocity tracking
movement and if I start up the scene
you'll see when I grab the instantaneous
Cube it moves instantly with my hand but
when I push it through the table it goes
right through and that's because it
disables the rigid body on it and the
same with the kinematic but the
kinematic has kind of a bit of a
floatiness to it it lags behind but
still goes through the table and finally
we have velocity tracking which has that
lagging but also stops when you try to
push it through the table and yeah that
is all of them boopping back to the
project I think it's important to
mention the attach transform and how
this essentially works is we'd have to
create an empty object here I'm going to
call it attach transform or actually
even better since this one's a little
long I'm going to choose the velocity
tracking one
you know I'm gonna go with attach point
I like that name better and so if we see
here this is going to be zeroed out on
our velocity tracking object and what we
want to keep in mind is we want to make
sure that this is set to local
in that the rotation is correct here and
what I mean by that is the x-axis this
red axis should be pointed towards the
palm of our hand the y-axis should be
pointed towards where we consider the
top and then the Z should be pointed
forwards now for this example let's say
I want the top of this surface to be
pointing forwards I want the V to be
pointing upwards and then I want this to
be pointing towards my palm so I would
switch to rotation and I would adjust
those accordingly
oop my bad I have the wrong thing
selected it's the attach point that we
need to rotate
all right so now we have the y-axis that
is pointing upwards and so my V should
be pointing upwards and then the x is
pointed towards my palm and then this
should be pointing forwards when I pick
it up now the last thing I need to make
sure I do is make sure that I set the
attach point so I'm going to come over
here I'm going to drag that there and
then let's boot up the scene now as you
see when I pick it up the V points
upward because the Y position was there
the X points towards the palm of my hand
and the Z points forward next we need to
look at interactable events and so these
are events where well if you imagine the
interact door comes in contact with our
interactable so that could be it
hovering that could be it selecting it
or deselecting it and we can use these
to do things like when we hover over it
maybe change the mesh so the player
knows that the object is interactable
and we could also do things like when we
select it maybe you want to make that
item active so maybe it turns on a
shield for the player and then you know
if we go over to the XR direct interact
tour we also have the same kind of
events that we can play with but even
more so we have these events so we have
audio events that we can trigger in
haptic events so on select entered you
might want to add in an audio clip and
play a sound for the player or when we
come over here we might want to do
haptic events this is really important
for immersion so again when they're
selecting when you grab something in
real life you kind of have a tactile
response and this little vibration and
duration that you can add here is going
to let the player know that okay they've
grabbed something and based on if it's a
heavier object maybe you want it to have
a very intense haptic feedback now when
it comes to interacting with objects you
know the basics of it as always I love
you my patreon members and I hope you
found this useful and I'll see you in
the next one bye
[Music]
Посмотреть больше похожих видео
5.0 / 5 (0 votes)