Skip to content

Interactable Objects

StoneFox edited this page Jun 8, 2016 · 2 revisions

[VRTK_InteractableObject]

The Interactable Object script is attached to any game object that is required to be interacted with (e.g. via the controllers).

The following script parameters are available:

######Touch Interactions

  • Highlight On Touch: The object will only highlight when a controller touches it if this is checked.
  • Touch Highligt Color: The colour to highlight the object when it is touched. This colour will override any globally set color (for instance on the VRTK_InteractTouch script).

######Grab Interactions

  • Is Grabbable: Determines if the object can be grabbed
  • Is Droppable: Determines if the object can be dropped by the controller grab button being used. If this is unchecked then it's not possible to drop the item once it's picked up using the controller button. It is still possible for the item to be dropped if the Grab Attach Mechanic is a joint and too much force is applied to the object and the joint is broken. To prevent this it's better to use the Child Of Controller mechanic.
  • Hold Button To Grab: If this is checked then the grab button on the controller needs to be continually held down to keep grabbing. If this is unchecked the grab button toggles the grab action with one button press to grab and another to release.
  • Pause Collisions On Grab: If this is checked then collisions with the Interactable Object are temporarily disabled whilst the object snaps to the controller. This is useful if a game object may get stuck inside another object when it is being grabbed.
  • Grab Snap Type: This sets the snap type of the object when it is grabbed.
  • Simple_Snap snaps the grabbed object's central position to the controller attach point (default is controller tip).
  • Rotation_Snap snaps the grabbed object to a specific rotation which is provided as a Vector3 in the Snap To Rotation parameter.
  • Precision_Snap does not snap the object's position to the controller and picks the object up at the point the controller is touching the object (like a real life hand picking something up).
  • Handle_Snap allows for an empty GameObject as a child of the interactable object to be used as the reference snap point. On grab, this empty GameObject rotation and position is used to orientate the grabbed interactable object to the controller.
  • Snap To Rotation: A Vector3 of EulerAngles that determines the rotation of the object in relation to the controller on snap. This is useful for picking up guns or swords where the relative rotation to the controller is important for ease of use.
  • Snap To Position: A Vector3 that determines the position of the object in relation to the controller on snap.
  • Snap Handle: A Transform provided as an empty game object which must be the child of the item being grabbed and serves as an orientation point to rotate and position the grabbed item in relation to the grabbing controller.

######Grab Mechanics

  • Grab Attach Type: This determines how the grabbed item will be attached to the controller when it is grabbed.
  • Fixed Joint attaches the object to the controller with a fixed joint meaning it tracks the position and rotation of the controller with perfect 1:1 tracking.
  • Spring Joint attaches the object to the controller with a spring joint meaing there is some flexibility between the item and the controller force moving the item. This works well when attempting to pull an item rather than snap the item directly to the controller. It creates the illusion that the item has resistence to move it.
  • Track Object doesn't attach the object to the controller via a joint, instead it ensures the object tracks the direction of the controller, which works well for items that are on hinged joints.
  • Child Of Controller simply makes the object a child of the controller grabbing so it naturally tracks the position of the controller motion.
  • Detach Threshold: The force amount when to detach the object from the grabbed controller. If the controller tries to exert a force higher than this threshold on the object (from pulling it through another object or pushing it into another object) then the joint holding the object to the grabbing controller will break and the object will no longer be grabbed. This also works with Tracked Object grabbing but determines how far the controller is from the object before breaking the grab.
  • Spring Joint Strength: The strength of the spring holding the object to the controller. A low number will mean the spring is very loose and the object will require more force to move it, a high number will mean a tight spring meaning less force is required to move it.
  • Spring Joint Damper: The amount to damper the spring effect when using a Spring Joint grab mechanic. A higher number here will reduce the oscillation effect when moving jointed Interactable Objects.
  • Throw Multiplier: An amount to multiply the velocity of the given object when it is thrown. This can also be used in conjunction with the Interact Grab Throw Multiplier to have certain objects be thrown even further than normal (or thrown a shorter distance if a number below 1 is entered).

######Use Interactions

  • Is Usable: Determines if the object can be used
  • Hold Button To Use: If this is checked then the use button on the controller needs to be continually held down to keep using. If this is unchecked the the use button toggles the use action with one button press to start using and another to stop using.
  • Pointer Activates Use Action: If this is checked then when a World Pointer beam (projected from the controller) hits the interactable object, if the object has Hold Button To Use unchecked then whilst the pointer is over the object it will run it's Using method. If Hold Button To Use is unchecked then the Using method will be run when the pointer is deactivated. The world pointer will not throw the Destination Set event if it is affecting an interactable object with this setting checked as this prevents unwanted teleporting from happening when using an object with a pointer.

The following events are emitted:

  • InteractableObjectTouched: Emitted when another object touches the current object.
  • InteractableObjectUntouched: Emitted when the other object stops touching the current object.
  • InteractableObjectGrabbed: Emitted when another object grabs the current object (e.g. a controller).
  • InteractableObjectUngrabbed: Emitted when the other object stops grabbing the current object.
  • InteractableObjectUsed: Emitted when another object uses the current object (e.g. a controller).
  • InteractableObjectUnused: Emitted when the other object stops using the current object.

The event payload that is emitted contains:

  • interactingObject: The object that is initiating the interaction (e.g. a controller)

The basis of this script is to provide a simple mechanism for identifying objects in the game world that can be grabbed or used but it is expected that this script is the base to be inherited into a script with richer functionality.

An example of the VRTK_InteractableObject can be viewed in the scene SteamVR_Unity_Toolkit/Examples/005_Controller_BasicObjectGrabbing. The scene also uses the VRTK_InteractTouch and VRTK_InteractGrab scripts on the controllers to show how an interactable object can be grabbed and snapped to the controller and thrown around the game world.

Another example can be viewed in the scene SteamVR_Unity_Toolkit/Examples/013_Controller_UsingAndGrabbingMultipleObjects. The scene shows mutltiple objects that can be grabbed by holding the buttons or grabbed by toggling the button click and also has objects that can have their Using state toggled to show how mutliple items can be turned on at the same time.

Clone this wiki locally