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

VRTK_InteractTouch

Overview

The Interact Touch script is attached to a Controller object within the [CameraRig] prefab.

Inspector Parameters

  • Hide Controller On Touch: Hides the controller model when a valid touch occurs.
  • Hide Controller Delay: The amount of seconds to wait before hiding the controller on touch.
  • Global Touch Highlight Color: If the interactable object can be highlighted when it's touched but no local colour is set then this global colour is used.
  • 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 HTC Vive 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/1

public void ToggleControllerRigidBody(bool state)

  • Parameters
  • bool state - The state of whether the rigidbody is on or off. true toggles the rigidbody on and false turns it off.
  • 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.

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.