Guides
Guides
These docs are for v3.1.0. Click to read the latest docs for v3.3.0.

VRTK_InteractTouch

Overview

The Interact Touch script is usually applied to a Controller and provides a collider to know when the controller is touching something.

Colliders are created for the controller and by default the selected controller SDK will have a set of colliders for the given default controller of that SDK.

A custom collider can be provided by the Custom Rigidbody Object parameter.

Inspector Parameters

  • Custom Rigidbody Object: If a custom rigidbody and collider for the rigidbody are required, then a gameobject containing a rigidbody and collider can be passed into this parameter. If this is empty then the rigidbody and collider will be auto generated at runtime to match the SDK default controller.

Class Events

  • ControllerTouchInteractableObject - Emitted when a valid object is touched.
  • ControllerUntouchInteractableObject - Emitted when a valid object is no longer being touched.

Unity Events

Adding the VRTK_InteractTouch_UnityEvents component to VRTK_InteractTouch object allows access to UnityEvents that will react identically to the Class Events.

  • OnControllerTouchInteractableObject - Emits the ControllerTouchInteractableObject class event.
  • OnControllerUntouchInteractableObject - Emits the ControllerUntouchInteractableObject class event.

Event Payload

  • uint controllerIndex - The index of the controller doing the interaction.
  • GameObject target - The GameObject of the interactable object that is being interacted with by the controller.

Class Methods

ForceTouch/1

public void ForceTouch(GameObject obj)

  • Parameters
  • GameObject obj - The game object to attempt to force touch.
  • Returns
  • none

The ForceTouch method will attempt to force the controller to touch the given game object. This is useful if an object that isn't being touched is required to be grabbed or used as the controller doesn't physically have to be touching it to be forced to interact with it.

GetTouchedObject/0

public GameObject GetTouchedObject()

  • Parameters
  • none
  • Returns
  • GameObject - The game object of what is currently being touched by this controller.

The GetTouchedObject method returns the current object being touched by the controller.

IsObjectInteractable/1

public bool IsObjectInteractable(GameObject obj)

  • Parameters
  • GameObject obj - The game object to check to see if it's interactable.
  • Returns
  • bool - Is true if the given object is of type VRTK_InteractableObject.

The IsObjectInteractable method is used to check if a given game object is of type VRTK_InteractableObject and whether the object is enabled.

ToggleControllerRigidBody/2

public void ToggleControllerRigidBody(bool state, bool forceToggle = false)

  • Parameters
  • bool state - The state of whether the rigidbody is on or off. true toggles the rigidbody on and false turns it off.
  • bool forceToggle - Determines if the rigidbody has been forced into it's new state by another script. This can be used to override other non-force settings. Defaults to false
  • Returns
  • none

The ToggleControllerRigidBody method toggles the controller's rigidbody's ability to detect collisions. If it is true then the controller rigidbody will collide with other collidable game objects.

IsRigidBodyActive/0

public bool IsRigidBodyActive()

  • Parameters
  • none
  • Returns
  • bool - Is true if the rigidbody on the controller is currently active and able to affect other scene rigidbodies.

The IsRigidBodyActive method checks to see if the rigidbody on the controller object is active and can affect other rigidbodies in the scene.

IsRigidBodyForcedActive/0

public bool IsRigidBodyForcedActive()

  • Parameters
  • none
  • Returns
  • bool - Is true if the rigidbody is active and has been forced into the active state.

The IsRigidBodyForcedActive method checks to see if the rigidbody on the controller object has been forced into the active state.

ForceStopTouching/0

public void ForceStopTouching()

  • Parameters
  • none
  • Returns
  • none

The ForceStopTouching method will stop the controller from touching an object even if the controller is physically touching the object still.

ControllerColliders/0

public Collider[] ControllerColliders()

  • Parameters
  • none
  • Returns
  • Collider[] - An array of colliders that are associated with the controller.

The ControllerColliders method retrieves all of the associated colliders on the controller.

Example

VRTK/Examples/005_Controller/BasicObjectGrabbing demonstrates the highlighting of objects that have the VRTK_InteractableObject script added to them to show the ability to highlight interactable objects when they are touched by the controllers.