Guides
These docs are for v3.2.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 Collider Container: An optional GameObject that contains the compound colliders to represent the touching object. If this is empty then the collider will be auto generated at runtime to match the SDK default controller.

Class Events

  • ControllerStartTouchInteractableObject - Emitted when the touch of a valid object has started.
  • ControllerTouchInteractableObject - Emitted when a valid object is touched.
  • ControllerStartUntouchInteractableObject - Emitted when the untouch of a valid object has started.
  • ControllerUntouchInteractableObject - Emitted when a valid object is no longer being touched.
  • ControllerRigidbodyActivated - Emitted when the controller rigidbody is activated.
  • ControllerRigidbodyDeactivated - Emitted when the controller rigidbody is deactivated.

Unity Events

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

  • All C# delegate events are mapped to a Unity Event with the On prefix. e.g. MyEvent -> OnMyEvent.

Event Payload

  • VRTK_ControllerReference controllerReference - The reference to 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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 virtual 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.