Guides

VRTK_InteractTouch

Overview

Determines if a GameObject can initiate a touch with an Interactable Object.

Required Components:

  • Rigidbody - A Unity kinematic Rigidbody to determine when collisions happen between the Interact Touch GameObject and other valid colliders.

Script Usage:

  • Place the VRTK_InteractTouch script on the controller script alias GameObject of the controller to track (e.g. Right Controller Script Alias).

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.

Class Methods

ForceTouch/1

public virtual void ForceTouch(GameObject obj)

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

The ForceTouch method will attempt to force the Interact Touch onto the given GameObject.

GetTouchedObject/0

public virtual GameObject GetTouchedObject()

  • Parameters
    • none
  • Returns
    • GameObject - The GameObject of what is currently being touched by this Interact Touch.

The GetTouchedObject method returns the current GameObject being touched by the Interact Touch.

IsObjectInteractable/1

public virtual bool IsObjectInteractable(GameObject obj)

  • Parameters
    • GameObject obj - The GameObject to check to see if it's a valid Interactable Object.
  • Returns
    • bool - Returns true if the given GameObjectis a valid Interactable Object.

The IsObjectInteractable method is used to check if a given GameObject is a valid Interactable Object.

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 Interact Touch rigidbody's ability to detect collisions. If it is true then the controller rigidbody will collide with other collidable GameObjects.

IsRigidBodyActive/0

public virtual bool IsRigidBodyActive()

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

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

IsRigidBodyForcedActive/0

public virtual bool IsRigidBodyForcedActive()

  • Parameters
    • none
  • Returns
    • bool - Returns 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 Interact Touch has been forced into the active state.

ForceStopTouching/0

public virtual void ForceStopTouching()

  • Parameters
    • none
  • Returns
    • none

The ForceStopTouching method will stop the Interact Touch from touching an Interactable Object even if the Interact Touch is physically touching the Interactable Object.

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 Interact Touch.

GetControllerType/0

public virtual SDK_BaseController.ControllerType GetControllerType()

  • Parameters
    • none
  • Returns
    • SDK_BaseController.ControllerType - The type of controller that the Interact Touch is attached to.

The GetControllerType method is a shortcut to retrieve the current controller type the Interact Touch is attached to.

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.