2023 Unity VR Basics - Grabbing Objects

Fist Full of Shrimp
13 Jul 202311:58

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

00:00

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

05:00

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

10:02

🎮 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

The 'XR Grab Interactable' refers to a component in virtual reality (VR) development that allows objects to be recognized as grabbable by the XR system. In the context of the video, this component is essential for enabling users to interact with objects within a VR environment. The script mentions adding this component to a 3D cube to make it grabbable, illustrating how it plays a central role in creating immersive VR experiences.

💡XR Direct Interactor

The 'XR Direct Interactor' is a component used in VR development to handle direct interactions with objects, such as grabbing. It requires a collider, typically a sphere collider set to trigger, to function properly. The video script describes adding this component to VR hand controllers, emphasizing its necessity for detecting and responding to user actions like grabbing objects within the VR space.

💡Collider

A 'Collider' in VR development is a component that detects and responds to collisions between objects. The video script specifically mentions the need for a sphere collider set to 'is trigger' for the XR Direct Interactor to work. This component is crucial for creating realistic interactions, as it enables the system to recognize when a user's hand (controller) comes into contact with an object that can be grabbed.

💡Interaction Manager

The 'Interaction Manager' is a component that oversees the interactions between interactors (like hands) and interactables (like grabbable objects) in a VR environment. The video script discusses this component in the context of the XR Direct Interactor, highlighting its role in managing how users interact with objects in VR. It's a key part of creating a seamless and intuitive user experience.

💡Interaction Layer Mask

The 'Interaction Layer Mask' is a feature that allows developers to specify which layers or groups of objects can interact with each other in a VR scene. The video script explains how to set this mask to limit interactions to only those objects on the 'interactable' layer, ensuring that UI components, for example, only interact with other UI elements and not with grabbable objects.

💡Select Action Trigger

The 'Select Action Trigger' determines how an object is selected or activated in VR. The video script outlines different selection modes such as 'States Change', 'State', 'Toggle', and 'Sticky', each offering different user interaction experiences. For instance, 'States Change' requires the grip button to be pressed to grab an object, while 'State' allows objects to be picked up just by touching them while holding the grip button.

💡Hide Controller on Select

The 'Hide Controller on Select' option is a feature that allows the VR system to hide the controller's visual representation when an object is selected. This can improve the visual realism of the VR experience, as demonstrated in the video script, where hiding the controller can prevent visual inconsistencies when objects are grabbed, especially if there's no custom animation for grabbing.

💡Starting Selected Interactable

The 'Starting Selected Interactable' is a setting that allows an object to be pre-selected or 'held' by the user at the start of a VR scene. The video script mentions this feature in the context of initializing a player with a specific object, like a gun, at the beginning of a game. This can be used to streamline the start of a VR experience by having necessary tools or items ready for immediate use.

💡Attach Transform

The 'Attach Transform' is a component that specifies where an object should attach to the hand controller when grabbed. The video script provides an example of creating an 'attach point' for an object, ensuring that when picked up, the object's orientation and position relative to the hand are correct. This is crucial for creating natural and intuitive object interactions in VR.

💡Interactable Events

Interactable events are triggers or actions that occur when an interactor comes into contact with an interactable object. The video script discusses using these events to change the mesh of an object when hovered over, indicating to the player that it is interactable. These events are part of creating a responsive and dynamic VR environment that provides feedback to the user's actions.

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

play00:00

let's talk about grabbing objects in VR

play00:02

and in order to grab things we're going

play00:05

to need to know how to use two

play00:06

components that being the XR grab

play00:09

interactable and the XR direct

play00:10

interactor as always I want to cover as

play00:13

much as possible in the smallest amount

play00:14

of time so let's get started opening up

play00:16

the project you'll see here I haven't

play00:18

really added anything new I do have this

play00:20

new object here that I'll go over later

play00:22

in the video but yeah we have the XR

play00:24

origin and then we have our left and

play00:25

right hand controllers let's kick things

play00:27

off by adding a XR direct interact to do

play00:31

that all we have to do is Select our two

play00:33

controllers here and I'm going to type

play00:34

in XR direct interactor and there we go

play00:37

we have the XR director interactor but

play00:38

it's also going to need some form of

play00:41

collider that's going to act as a

play00:42

trigger without that this will not work

play00:44

so I'm going to add a sphere collider

play00:46

and expand this out I'm going to set it

play00:48

to is trigger and then we have a pretty

play00:50

big radius here so we need to reduce it

play00:53

down and you know I'm just going to grab

play00:55

the hand model for a reference let's see

play00:57

where is my yeah let's go with the right

play00:59

hand and I'll just drag this into the

play01:01

scene make sure it's zeroed out

play01:04

all right and so I'm going to take this

play01:06

radius and reduce it I'm going to try

play01:08

point one and you see that is just about

play01:11

the right size you know you could try

play01:13

something like

play01:14

.08 if you want it to be a little more

play01:18

exact for when your hand interacts with

play01:21

an object and then we just have to make

play01:22

sure that we do this for the left hand

play01:24

as well yeah you know I like .08 a

play01:27

little better and then I'm just going to

play01:28

get rid of this reference so with that

play01:30

let's go over the director interactor

play01:32

looking through some of these components

play01:34

you can see we have an interaction

play01:35

manager so that is going to be handling

play01:37

the interaction between our interactor

play01:39

which is going to be our hand and then

play01:41

the interactable which will be the

play01:43

objects that we can pick up next we have

play01:45

an interaction layer mask so we might

play01:47

not want to interact with every single

play01:49

object in the scene sometimes you want

play01:51

your UI components to just interact with

play01:53

UI components and so this is where we

play01:56

would add a layer to separate these

play01:58

interactions and you just click add

play02:00

layer and we could add one here called

play02:01

the interactable

play02:03

coming back to our hands so you know I

play02:06

could say uh I don't want this to

play02:07

interact with anything I only want

play02:08

things to interact with the interactable

play02:10

layer and then down here we have an

play02:12

attached transform so if you do not have

play02:15

anything here and this is set to none

play02:17

it's just going to use the transform of

play02:20

the XR direct interactor which I'm okay

play02:22

with right now we also have select

play02:24

action trigger so this would determine

play02:26

how our select starts so it's kind of

play02:30

interesting so States change is how you

play02:32

would expect you know you go down you

play02:33

grab an object and then when you pick it

play02:36

up you know you're holding the grip

play02:38

button but when you release it it drops

play02:39

the other ones we have is state so how

play02:42

State works is when you go in and you

play02:44

are holding the button even if you are

play02:47

not interacting with the object if you

play02:49

ran into it while holding the grip

play02:51

button it would pick it up which is kind

play02:52

of a weird interaction but there it is

play02:54

we also have toggle and sticky and

play02:57

toggle and sticky are very similar in

play02:58

the sense that you would be hovering

play03:00

over a object and when it's togg you can

play03:04

press the grip button or whatever your

play03:06

activation button is and then when you

play03:08

release it it'll still stay on you but

play03:10

when you press it again then it will

play03:12

release and how sticky works is the same

play03:15

way but it only lets go of the object

play03:17

when you let go for this second time so

play03:20

yeah there you go a few options on how

play03:22

you can pick up your objects we also

play03:25

have hide controller on select and you

play03:27

know I'm going to select both my left

play03:28

and right hand controller and I'm just

play03:30

going to check that so if you don't have

play03:31

a custom animation or dynamic grabbing

play03:34

for your objects it kind of looks a

play03:37

little wonky the hand will go right

play03:38

through the object and personally I like

play03:40

to hide the controller on select but you

play03:43

know actually for demonstration purposes

play03:44

later I'm going to check this off for

play03:46

now we also have the odd choice right

play03:49

here of starting selected interactable

play03:51

so if we boot up the scene and head

play03:53

something here if we had something that

play03:54

was a XR grab interactable then this

play03:57

would just start off in our hand at the

play03:59

beginning of the scene so say you want

play04:01

the player just to have a gun in their

play04:02

hand at the beginning this is where you

play04:04

could put that and finally we have a

play04:06

bunch of events here audio events haptic

play04:08

events in interactor events that we can

play04:11

use when we pick up our objects but we

play04:15

don't have any objects to pick up so

play04:17

let's fix that now in order to grab

play04:19

things we need grab interactables and

play04:21

well just objects to grab them so I am

play04:24

going to activate this and show you what

play04:25

I've done here and as you can see I'm

play04:28

actually going to hide these for now all

play04:30

I have here is a table and the table is

play04:32

just comprised of a cube that I made I

play04:35

put a 0.5 position and scale of one and

play04:39

yeah this is just a simple little table

play04:41

so we can grab onto things and you'll

play04:43

see the XR origin is right here so when

play04:45

we start up the scene we'll be looking

play04:47

at this table and be able to grab things

play04:48

off it and well let's make a grab

play04:51

interactable so to do that we need to

play04:53

right click grab a 3D cube I am going to

play04:56

reduce this to let's see 0.2 might be a

play05:00

good size yeah just for now and there we

play05:03

go next we need to add a well grab

play05:07

interactable component to it so I'm

play05:08

going to come over here add X our grab

play05:10

interactable and one thing I want to

play05:12

point out is you'll notice that it added

play05:14

a rigid body right here XR grab

play05:17

interactables will not work without a

play05:18

rigid body you kind of like how our

play05:20

hands will not work without a sphere

play05:22

collider set to trigger or any collider

play05:25

set to trigger we need to have a rigid

play05:27

body on our XR grab interactables and

play05:29

also some form of collider as well one

play05:32

thing I'll point out about the rigid

play05:33

body is you might want to up the

play05:36

Collision detection so I'm going to set

play05:38

this to continuous Dynamic and this is

play05:40

going to be a little more expensive than

play05:42

doing something like discrete or

play05:43

continuous but it does help prevent

play05:45

objects from flying through the ground

play05:47

when they're going at higher speeds if

play05:49

you're ever having those problems where

play05:51

the colliders aren't really picking

play05:52

things up you might want to consider

play05:54

continuous Dynamic expanding this out

play05:57

let's go over some things for the grab

play05:59

interact you'll see here that it has the

play06:01

interaction manager from before the one

play06:03

that is responsible for handling our

play06:04

interactions between our interactables

play06:06

and interact doors we also have the

play06:09

interaction layer mask and this is set

play06:10

to default and if you remember just a

play06:12

second ago I set this to only

play06:14

interactable so we need to make sure

play06:16

that this is set to the proper one so

play06:19

I'm going to oh where is it there we go

play06:22

and there we go I'm going to set it to

play06:25

interactable take it off default we also

play06:27

have different types of Select mode so

play06:29

there is single and multiple just for

play06:30

this one I'm just going to cover single

play06:32

we'll cover multiple hand grabbing

play06:34

objects later we have a gaze

play06:36

configuration which well I can't afford

play06:38

the Oculus Pro or any other eye tracking

play06:41

device so I can't cover it sorry but hey

play06:44

I do have a patreon if you want to help

play06:45

me out with that patreon plug seriously

play06:48

though just a like would be enough if

play06:49

you're finding this video helpful but

play06:51

yeah all right let's move on uh we also

play06:53

have different movement types I will

play06:55

cover this in a second we also can

play06:57

determine if we want the object to track

play06:59

or not so if we don't want it to track

play07:02

let's say the position we could turn

play07:04

that off here or if you want the rate

play07:06

rotation of the object to be maintained

play07:08

so even though we're turning our

play07:10

controllers then if we turn this off it

play07:12

wouldn't turn with it it just moves the

play07:14

position we can also decide to smooth

play07:16

this out and so this kind of gives you a

play07:18

bit of a floaty feel that you can play

play07:20

with same with the road rotation we also

play07:22

have a ton of options when it comes to

play07:24

throwing and so we can determine if we

play07:27

want to throw on detach or just drop it

play07:29

immediately and not track the velocity

play07:31

and we can play with this later I'm

play07:33

going to try to make a video that

play07:35

perfects throwing because well for the

play07:37

game Jam I made a game where you

play07:39

primarily throw things and God did I

play07:41

hate my throwing but right and then we

play07:43

have attached transforms where we can

play07:45

specifically say where I pick up an

play07:47

object I want you to attach exactly at

play07:50

this location and I will cover that in

play07:53

just one second now I know I keep saying

play07:55

one second and that one second has

play07:57

passed so let's cover what the movement

play07:59

types are so I'm going to go ahead and

play08:01

click this off

play08:03

and I'm going to activate these three

play08:05

cubes and as you can see here there's

play08:07

nothing crazy going on I've just put a

play08:10

little canvas on these to symbolize what

play08:13

these are going to stand for and so what

play08:15

we have here is a cube with kinematic

play08:18

instantaneous and velocity tracking

play08:20

movement and if I start up the scene

play08:22

you'll see when I grab the instantaneous

play08:25

Cube it moves instantly with my hand but

play08:28

when I push it through the table it goes

play08:30

right through and that's because it

play08:32

disables the rigid body on it and the

play08:34

same with the kinematic but the

play08:35

kinematic has kind of a bit of a

play08:37

floatiness to it it lags behind but

play08:40

still goes through the table and finally

play08:41

we have velocity tracking which has that

play08:44

lagging but also stops when you try to

play08:47

push it through the table and yeah that

play08:49

is all of them boopping back to the

play08:51

project I think it's important to

play08:53

mention the attach transform and how

play08:56

this essentially works is we'd have to

play08:58

create an empty object here I'm going to

play08:59

call it attach transform or actually

play09:01

even better since this one's a little

play09:03

long I'm going to choose the velocity

play09:04

tracking one

play09:06

you know I'm gonna go with attach point

play09:08

I like that name better and so if we see

play09:11

here this is going to be zeroed out on

play09:13

our velocity tracking object and what we

play09:15

want to keep in mind is we want to make

play09:17

sure that this is set to local

play09:19

in that the rotation is correct here and

play09:23

what I mean by that is the x-axis this

play09:26

red axis should be pointed towards the

play09:28

palm of our hand the y-axis should be

play09:30

pointed towards where we consider the

play09:32

top and then the Z should be pointed

play09:34

forwards now for this example let's say

play09:36

I want the top of this surface to be

play09:38

pointing forwards I want the V to be

play09:41

pointing upwards and then I want this to

play09:43

be pointing towards my palm so I would

play09:45

switch to rotation and I would adjust

play09:48

those accordingly

play09:50

oop my bad I have the wrong thing

play09:52

selected it's the attach point that we

play09:55

need to rotate

play09:56

all right so now we have the y-axis that

play09:59

is pointing upwards and so my V should

play10:02

be pointing upwards and then the x is

play10:05

pointed towards my palm and then this

play10:07

should be pointing forwards when I pick

play10:08

it up now the last thing I need to make

play10:10

sure I do is make sure that I set the

play10:12

attach point so I'm going to come over

play10:13

here I'm going to drag that there and

play10:16

then let's boot up the scene now as you

play10:18

see when I pick it up the V points

play10:19

upward because the Y position was there

play10:21

the X points towards the palm of my hand

play10:24

and the Z points forward next we need to

play10:27

look at interactable events and so these

play10:29

are events where well if you imagine the

play10:31

interact door comes in contact with our

play10:34

interactable so that could be it

play10:36

hovering that could be it selecting it

play10:38

or deselecting it and we can use these

play10:40

to do things like when we hover over it

play10:42

maybe change the mesh so the player

play10:44

knows that the object is interactable

play10:46

and we could also do things like when we

play10:48

select it maybe you want to make that

play10:51

item active so maybe it turns on a

play10:54

shield for the player and then you know

play10:56

if we go over to the XR direct interact

play10:59

tour we also have the same kind of

play11:01

events that we can play with but even

play11:03

more so we have these events so we have

play11:05

audio events that we can trigger in

play11:06

haptic events so on select entered you

play11:09

might want to add in an audio clip and

play11:11

play a sound for the player or when we

play11:14

come over here we might want to do

play11:16

haptic events this is really important

play11:17

for immersion so again when they're

play11:19

selecting when you grab something in

play11:21

real life you kind of have a tactile

play11:22

response and this little vibration and

play11:25

duration that you can add here is going

play11:27

to let the player know that okay they've

play11:30

grabbed something and based on if it's a

play11:32

heavier object maybe you want it to have

play11:34

a very intense haptic feedback now when

play11:37

it comes to interacting with objects you

play11:40

know the basics of it as always I love

play11:43

you my patreon members and I hope you

play11:46

found this useful and I'll see you in

play11:47

the next one bye

play11:49

[Music]

Rate This

5.0 / 5 (0 votes)

Ähnliche Tags
VR DevelopmentXR InteractableXR Direct InteractorVirtual RealityGrab MechanicsUnity TutorialVR InteractionGame DevelopmentVR GrabbingInteractive Design
Benötigen Sie eine Zusammenfassung auf Englisch?