-
Notifications
You must be signed in to change notification settings - Fork 0
Grabbing Interactable Objects
[VRTK_InteractGrab]
The Interact Grab script is attached to a Controller object
within the [CameraRig] prefab and the Controller object
requires the VRTK_ControllerEvents script to be attached as it
uses this for listening to the controller button events for grabbing
and releasing interactable game objects. It listens for the
AliasGrabOn and AliasGrabOff events to determine when an object
should be grabbed and should be released.
The Controller object also requires the VRTK_InteractTouch script
to be attached to it as this is used to determine when an interactable
object is being touched. Only valid touched objects can be grabbed.
An object can be grabbed if the Controller touches a game object which
contains the VRTK_InteractableObject script and has the flag
isGrabbable set to true.
If a valid interactable object is grabbable then pressing the set
Grab button on the Controller (default is Trigger) will grab and
snap the object to the controller and will not release it until the
Grab button is released.
When the Controller Grab button is released, if the interactable
game object is grabbable then it will be propelled in the direction
and at the velocity the controller was at, which can simulate object
throwing.
The interactable objects require a collider to activate the trigger and a rigidbody to pick them up and move them around the game world.
The following script parameters are available:
- Controller Attach Point: The rigidbody point on the controller model to snap the grabbed object to (defaults to the tip)
- Hide Controller On Grab: Hides the controller model when a valid grab occurs
- Hide Controller Delay: The amount of seconds to wait before hiding the controller on grab.
- Grab Precognition: An amount of time between when the grab button is pressed to when the controller is touching something to grab it. For example, if an object is falling at a fast rate, then it is very hard to press the grab button in time to catch the object due to human reaction times. A higher number here will mean the grab button can be pressed before the controller touches the object and when the collision takes place, if the grab button is still being held down then the grab action will be successful.
- Throw Multiplier: An amount to multiply the velocity of any objects being thrown. This can be useful when scaling up the CameraRig to simulate being able to throw items further.
- Create Rigid Body When Not Touching: If this is checked and the controller is not touching an Interactable Object when the grab button is pressed then a rigid body is added to the controller to allow the controller to push other rigid body objects around.
The following events are emitted:
- ControllerGrabInteractableObject: Emitted when a valid object is grabbed
- ControllerUngrabInteractableObject: Emitted when a valid object is released from being grabbed
The event payload that is emitted contains:
- controllerIndex: The index of the controller doing the interaction
- target: The GameObject of the interactable object that is being interacted with by the controller
An example of the VRTK_InteractGrab can be viewed in the
scene SteamVR_Unity_Toolkit/Examples/005_Controller/BasicObjectGrabbing.
The scene demonstrates the grabbing of interactable objects that have
the VRTK_InteractableObject script attached to them. The objects can
be picked up and thrown around.
More complex examples can be viewed in the scene
SteamVR_Unity_Toolkit/Examples/013_Controller_UsingAndGrabbingMultipleObjects
which demonstrates that each controller can grab and use objects
independently and objects can also be toggled to their use state
simultaneously. The scene
SteamVR_Unity_Toolkit/Examples/014_Controller_SnappingObjectsOnGrab
demonstrates the different mechanisms for snapping a grabbed object to
the controller.
- Home
- Quick Start
- FAQ/Troubleshooting
- Prefabs
-
Scripts
- Controllers
- Pointers
- Movement
- Interactions
- Examples