{"_id":"594949e82be16d0026ec0537","category":{"_id":"594949e62be16d0026ec04d4","version":"594949e52be16d0026ec04cd","project":"571fa55ca0acd42000af9545","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-01-01T16:45:52.489Z","from_sync":false,"order":6,"slug":"interactions","title":"Interactions"},"parentDoc":null,"user":"571fa519db52d01700f5cf3d","project":"571fa55ca0acd42000af9545","version":{"_id":"594949e52be16d0026ec04cd","project":"571fa55ca0acd42000af9545","__v":2,"createdAt":"2017-06-20T16:14:29.816Z","releaseDate":"2017-06-20T16:14:29.816Z","categories":["594949e62be16d0026ec04ce","594949e62be16d0026ec04cf","594949e62be16d0026ec04d0","594949e62be16d0026ec04d1","594949e62be16d0026ec04d2","594949e62be16d0026ec04d3","594949e62be16d0026ec04d4","594949e62be16d0026ec04d5","594949e62be16d0026ec04d6","594949e62be16d0026ec04d7","594949e62be16d0026ec04d8","594949e62be16d0026ec04d9","594949e62be16d0026ec04da","594949e62be16d0026ec04db","594949e62be16d0026ec04dc","594949e62be16d0026ec04dd","594949e62be16d0026ec04de","594949e62be16d0026ec04df","594949e62be16d0026ec04e0","594949e62be16d0026ec04e1","59497219f4a8980024dd0631"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Kunekune","version_clean":"3.2.0","version":"3.2.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T16:47:18.600Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"## Overview\n\nThe Interact Grab script is attached to a Controller object and requires the `VRTK_ControllerEvents` script to be attached as it uses this for listening to the controller button events for grabbing and releasing interactable game objects.\n\nIt listens for the `AliasGrabOn` and `AliasGrabOff` events to determine when an object should be grabbed and should be released.\n\nThe Controller object also requires the `VRTK_InteractTouch` script to be attached to it as this is used to determine when an interactable object is being touched. Only valid touched objects can be grabbed.\n\nAn object can be grabbed if the Controller touches a game object which contains the `VRTK_InteractableObject` script and has the flag `isGrabbable` set to `true`.\n\nIf a valid interactable object is grabbable then pressing the set `Grab` button on the Controller (default is `Grip`) will grab and snap the object to the controller and will not release it until the `Grab` button is released.\n\nWhen the Controller `Grab` button is released, if the interactable game object is grabbable then it will be propelled in the direction and at the velocity the controller was at, which can simulate object throwing.\n\nThe interactable objects require a collider to activate the trigger and a rigidbody to pick them up and move them around the game world.\n\n## Inspector Parameters\n\n * **Grab Button:** The button used to grab/release a touched object.\n * **Grab Precognition:** An amount of time between when the grab button is pressed to when the controller is touching something to grab it. For example, if an object is falling at a fast rate, then it is very hard to press the grab button in time to catch the object due to human reaction times. A higher number here will mean the grab button can be pressed before the controller touches the object and when the collision takes place, if the grab button is still being held down then the grab action will be successful.\n * **Throw Multiplier:** An amount to multiply the velocity of any objects being thrown. This can be useful when scaling up the play area to simulate being able to throw items further.\n * **Create Rigid Body When Not Touching:** If this is checked and the controller is not touching an Interactable Object when the grab button is pressed then a rigid body is added to the controller to allow the controller to push other rigid body objects around.\n * **Controller Attach Point:** The rigidbody point on the controller model to snap the grabbed object to. If blank it will be set to the SDK default.\n * **Controller Events:** The controller to listen for the events on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.\n * **Interact Touch:** The Interact Touch to listen for touches on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.\n\n## Class Events\n\n * `GrabButtonPressed` - Emitted when the grab button is pressed.\n * `GrabButtonReleased` - Emitted when the grab button is released.\n * `ControllerStartGrabInteractableObject` - Emitted when a grab of a valid object is started.\n * `ControllerGrabInteractableObject` - Emitted when a valid object is grabbed.\n * `ControllerStartUngrabInteractableObject` - Emitted when a ungrab of a valid object is started.\n * `ControllerUngrabInteractableObject` - Emitted when a valid object is released from being grabbed.\n\n## Unity Events\n\nAdding the `VRTK_InteractGrab_UnityEvents` component to `VRTK_InteractGrab` object allows access to `UnityEvents` that will react identically to the Class Events.\n\n * All C# delegate events are mapped to a Unity Event with the `On` prefix. e.g. `MyEvent` -> `OnMyEvent`.\n\n## Class Methods\n\n### IsGrabButtonPressed/0\n\n  > `public virtual bool IsGrabButtonPressed()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the grab alias button is being held down.\n\nThe IsGrabButtonPressed method determines whether the current grab alias button is being pressed down.\n\n### ForceRelease/1\n\n  > `public virtual void ForceRelease(bool applyGrabbingObjectVelocity = false)`\n\n  * Parameters\n   * `bool applyGrabbingObjectVelocity` - If this is true then upon releasing the object any velocity on the grabbing object will be applied to the object to essentiall throw it. Defaults to `false`.\n  * Returns\n   * _none_\n\nThe ForceRelease method will force the controller to stop grabbing the currently grabbed object.\n\n### AttemptGrab/0\n\n  > `public virtual void AttemptGrab()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * _none_\n\nThe AttemptGrab method will attempt to grab the currently touched object without needing to press the grab button on the controller.\n\n### GetGrabbedObject/0\n\n  > `public virtual GameObject GetGrabbedObject()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `GameObject` - The game object of what is currently being grabbed by this controller.\n\nThe GetGrabbedObject method returns the current object being grabbed by the controller.\n\n## Example\n\n`VRTK/Examples/005_Controller/BasicObjectGrabbing` demonstrates the grabbing of interactable objects that have the `VRTK_InteractableObject` script attached to them. The objects can be picked up and thrown around.\n\n`VRTK/Examples/013_Controller_UsingAndGrabbingMultipleObjects` demonstrates that each controller can grab and use objects independently and objects can also be toggled to their use state simultaneously.\n\n`VRTK/Examples/014_Controller_SnappingObjectsOnGrab` demonstrates the different mechanisms for snapping a grabbed object to the controller.","excerpt":"","slug":"vrtk_interactgrab","type":"basic","title":"VRTK_InteractGrab"}
## Overview The Interact Grab script is attached to a Controller object and requires the `VRTK_ControllerEvents` script to be attached as it uses this for listening to the controller button events for grabbing and releasing interactable game objects. It listens for the `AliasGrabOn` and `AliasGrabOff` events to determine when an object should be grabbed and should be released. The Controller object also requires the `VRTK_InteractTouch` script to be attached to it as this is used to determine when an interactable object is being touched. Only valid touched objects can be grabbed. An object can be grabbed if the Controller touches a game object which contains the `VRTK_InteractableObject` script and has the flag `isGrabbable` set to `true`. If a valid interactable object is grabbable then pressing the set `Grab` button on the Controller (default is `Grip`) will grab and snap the object to the controller and will not release it until the `Grab` button is released. When the Controller `Grab` button is released, if the interactable game object is grabbable then it will be propelled in the direction and at the velocity the controller was at, which can simulate object throwing. The interactable objects require a collider to activate the trigger and a rigidbody to pick them up and move them around the game world. ## Inspector Parameters * **Grab Button:** The button used to grab/release a touched object. * **Grab Precognition:** An amount of time between when the grab button is pressed to when the controller is touching something to grab it. For example, if an object is falling at a fast rate, then it is very hard to press the grab button in time to catch the object due to human reaction times. A higher number here will mean the grab button can be pressed before the controller touches the object and when the collision takes place, if the grab button is still being held down then the grab action will be successful. * **Throw Multiplier:** An amount to multiply the velocity of any objects being thrown. This can be useful when scaling up the play area to simulate being able to throw items further. * **Create Rigid Body When Not Touching:** If this is checked and the controller is not touching an Interactable Object when the grab button is pressed then a rigid body is added to the controller to allow the controller to push other rigid body objects around. * **Controller Attach Point:** The rigidbody point on the controller model to snap the grabbed object to. If blank it will be set to the SDK default. * **Controller Events:** The controller to listen for the events on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime. * **Interact Touch:** The Interact Touch to listen for touches on. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime. ## Class Events * `GrabButtonPressed` - Emitted when the grab button is pressed. * `GrabButtonReleased` - Emitted when the grab button is released. * `ControllerStartGrabInteractableObject` - Emitted when a grab of a valid object is started. * `ControllerGrabInteractableObject` - Emitted when a valid object is grabbed. * `ControllerStartUngrabInteractableObject` - Emitted when a ungrab of a valid object is started. * `ControllerUngrabInteractableObject` - Emitted when a valid object is released from being grabbed. ## Unity Events Adding the `VRTK_InteractGrab_UnityEvents` component to `VRTK_InteractGrab` 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`. ## Class Methods ### IsGrabButtonPressed/0 > `public virtual bool IsGrabButtonPressed()` * Parameters * _none_ * Returns * `bool` - Returns true if the grab alias button is being held down. The IsGrabButtonPressed method determines whether the current grab alias button is being pressed down. ### ForceRelease/1 > `public virtual void ForceRelease(bool applyGrabbingObjectVelocity = false)` * Parameters * `bool applyGrabbingObjectVelocity` - If this is true then upon releasing the object any velocity on the grabbing object will be applied to the object to essentiall throw it. Defaults to `false`. * Returns * _none_ The ForceRelease method will force the controller to stop grabbing the currently grabbed object. ### AttemptGrab/0 > `public virtual void AttemptGrab()` * Parameters * _none_ * Returns * _none_ The AttemptGrab method will attempt to grab the currently touched object without needing to press the grab button on the controller. ### GetGrabbedObject/0 > `public virtual GameObject GetGrabbedObject()` * Parameters * _none_ * Returns * `GameObject` - The game object of what is currently being grabbed by this controller. The GetGrabbedObject method returns the current object being grabbed by the controller. ## Example `VRTK/Examples/005_Controller/BasicObjectGrabbing` demonstrates the grabbing of interactable objects that have the `VRTK_InteractableObject` script attached to them. The objects can be picked up and thrown around. `VRTK/Examples/013_Controller_UsingAndGrabbingMultipleObjects` demonstrates that each controller can grab and use objects independently and objects can also be toggled to their use state simultaneously. `VRTK/Examples/014_Controller_SnappingObjectsOnGrab` demonstrates the different mechanisms for snapping a grabbed object to the controller.