{"__v":0,"_id":"58796781cd4a9c37007c9726","category":{"version":"58796781cd4a9c37007c96ef","project":"571fa55ca0acd42000af9545","_id":"58796781cd4a9c37007c96f8","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-01-01T16:58:11.374Z","from_sync":false,"order":10,"slug":"presence","title":"Presence"},"parentDoc":null,"project":"571fa55ca0acd42000af9545","user":"571fa519db52d01700f5cf3d","version":{"__v":4,"_id":"58796781cd4a9c37007c96ef","project":"571fa55ca0acd42000af9545","createdAt":"2017-01-13T23:49:21.393Z","releaseDate":"2017-01-13T23:49:21.393Z","categories":["58796781cd4a9c37007c96f0","58796781cd4a9c37007c96f1","58796781cd4a9c37007c96f2","58796781cd4a9c37007c96f3","58796781cd4a9c37007c96f4","58796781cd4a9c37007c96f5","58796781cd4a9c37007c96f6","58796781cd4a9c37007c96f7","58796781cd4a9c37007c96f8","58796781cd4a9c37007c96f9","58796781cd4a9c37007c96fa","58796781cd4a9c37007c96fb","58796781cd4a9c37007c96fc","58796781cd4a9c37007c96fd","58796781cd4a9c37007c96fe","58796781cd4a9c37007c96ff","58796781cd4a9c37007c9700","58b157ca1756cf370022f90d","58b1596f5dae732f00adeca2","58b1605a5dae732f00adecb1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Mukota","version_clean":"3.1.0","version":"3.1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T16:59:20.243Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"> extends [VRTK_DestinationMarker](doc:vrtk_destinationmarker)\n\n## Overview\n\nThe body physics script deals with how a user's body in the scene reacts to world physics and how to handle drops.\n\nThe body physics creates a rigidbody and collider for where the user is standing to allow physics interactions and prevent walking through walls.\n\nUpon actually moving in the play area, the rigidbody is set to kinematic to prevent the world from being pushed back in the user's view reducing sickness.\n\nThe body physics script also deals with snapping a user to the nearest floor if they look over a ledge or walk up stairs then it will move the play area to simulate movement in the scene.\n\nTo allow for peeking over a ledge and not falling, a fall restiction can happen by keeping a controller over the existing floor and the snap to the nearest floor will not happen until the controllers are also over the floor.\n\n## Inspector Parameters\n\n * **Enable Body Collisions:** If checked then the body collider and rigidbody will be used to check for rigidbody collisions.\n * **Ignore Grabbed Collisions:** If this is checked then any items that are grabbed with the controller will not collide with the body collider. This is very useful if the user is required to grab and wield objects because if the collider was active they would bounce off the collider.\n * **Headset Y Offset:** The collider which is created for the user is set at a height from the user's headset position. If the collider is required to be lower to allow for room between the play area collider and the headset then this offset value will shorten the height of the generated collider.\n * **Movement Threshold:** The amount of movement of the headset between the headset's current position and the current standing position to determine if the user is walking in play space and to ignore the body physics collisions if the movement delta is above this threshold.\n * **Standing History Samples:** The maximum number of samples to collect of headset position before determining if the current standing position within the play space has changed.\n * **Lean Y Threshold:** The `y` distance between the headset and the object being leaned over, if object being leaned over is taller than this threshold then the current standing position won't be updated.\n * **Layers To Ignore:** The layers to ignore when raycasting to find floors.\n * **Fall Restriction:** A check to see if the drop to nearest floor should take place. If the selected restrictor is still over the current floor then the drop to nearest floor will not occur. Works well for being able to lean over ledges and look down. Only works for falling down not teleporting up.\n * **Gravity Fall Y Threshold:** When the `y` distance between the floor and the headset exceeds this distance and `Enable Body Collisions` is true then the rigidbody gravity will be used instead of teleport to drop to nearest floor.\n * **Blink Y Threshold:** The `y` distance between the floor and the headset that must change before a fade transition is initiated. If the new user location is at a higher distance than the threshold then the headset blink transition will activate on teleport. If the new user location is within the threshold then no blink transition will happen, which is useful for walking up slopes, meshes and terrains to prevent constant blinking.\n * **Floor Height Tolerance:** The amount the `y` position needs to change by between the current floor `y` position and the previous floor `y` position before a change in floor height is considered to have occurred. A higher value here will mean that a `Drop To Floor` will be less likely to happen if the `y` of the floor beneath the user hasn't changed as much as the given threshold.\n\n## Class Variables\n\n * `public enum FallingRestrictors` - Options for testing if a play space fall is valid\n  * `No_Restriction` - Always drop to nearest floor when the headset is no longer over the current standing object.\n  * `Left_Controller` - Don't drop to nearest floor  if the Left Controller is still over the current standing object even if the headset isn't.\n  * `Right_Controller` - Don't drop to nearest floor  if the Right Controller is still over the current standing object even if the headset isn't.\n  * `Either_Controller` - Don't drop to nearest floor  if Either Controller is still over the current standing object even if the headset isn't.\n  * `Both_Controllers` - Don't drop to nearest floor only if Both Controllers are still over the current standing object even if the headset isn't.\n\n## Class Events\n\n * `StartFalling` - Emitted when a fall begins.\n * `StopFalling` - Emitted when a fall ends.\n * `StartMoving` - Emitted when movement in the play area begins.\n * `StopMoving` - Emitted when movement in the play area ends\n * `StartColliding` - Emitted when the body collider starts colliding with another game object\n * `StopColliding` - Emitted when the body collider stops colliding with another game object\n\n## Unity Events\n\nAdding the `VRTK_BodyPhysics_UnityEvents` component to `VRTK_BodyPhysics` object allows access to `UnityEvents` that will react identically to the Class Events.\n\n * `OnStartFalling` - Emits the StartFalling class event.\n * `OnStopFalling` - Emits the StopFalling class event.\n * `OnStartMoving` - Emits the StartMoving class event.\n * `OnStopMoving` - Emits the StopMoving class event.\n * `OnStartColliding` - Emits the StartColliding class event.\n * `OnStopColliding` - Emits the StopColliding class event.\n\n## Event Payload\n\n * `GameObject target` - The target the event is dealing with.\n\n## Class Methods\n\n### ArePhysicsEnabled/0\n\n  > `public bool ArePhysicsEnabled()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the body physics will interact with other scene physics objects and false if the body physics will ignore other scene physics objects.\n\nThe ArePhysicsEnabled method determines whether the body physics are set to interact with other scene physics objects.\n\n### ApplyBodyVelocity/3\n\n  > `public void ApplyBodyVelocity(Vector3 velocity, bool forcePhysicsOn = false, bool applyMomentum = false)`\n\n  * Parameters\n   * `Vector3 velocity` - The velocity to apply.\n   * `bool forcePhysicsOn` - If true will toggle the body collision physics back on if enable body collisions is true.\n   * `bool applyMomentum` - If true then the existing momentum of the play area will be applied as a force to the resulting velocity.\n  * Returns\n   * _none_\n\nThe ApplyBodyVelocity method applies a given velocity to the rigidbody attached to the body physics.\n\n### ToggleOnGround/1\n\n  > `public void ToggleOnGround(bool state)`\n\n  * Parameters\n   * `bool state` - If true then body physics are set to being on the ground.\n  * Returns\n   * _none_\n\nThe ToggleOnGround method sets whether the body is considered on the ground or not.\n\n### TogglePreventSnapToFloor/1\n\n  > `public void TogglePreventSnapToFloor(bool state)`\n\n  * Parameters\n   * `bool state` - If true the the snap to floor mechanic will not execute.\n  * Returns\n   * _none_\n\nThe PreventSnapToFloor method sets whether the snap to floor mechanic should be used.\n\n### IsFalling/0\n\n  > `public bool IsFalling()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the body is currently falling via gravity or via teleport.\n\nThe IsFalling method returns the falling state of the body.\n\n### IsMoving/0\n\n  > `public bool IsMoving()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the user is currently walking around their play area space.\n\nThe IsMoving method returns the moving within play area state of the body.\n\n### IsLeaning/0\n\n  > `public bool IsLeaning()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the user is considered to be leaning over an object.\n\nThe IsLeaning method returns the leaning state of the user.\n\n### OnGround/0\n\n  > `public bool OnGround()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the play area is on the ground and false if the play area is in the air.\n\nThe OnGround method returns whether the user is currently standing on the ground or not.\n\n## Example\n\n`VRTK/Examples/017_CameraRig_TouchpadWalking` has a collection of walls and slopes that can be traversed by the user with the touchpad but the user cannot pass through the objects as they are collidable and the rigidbody physics won't allow the intersection to occur.","excerpt":"","slug":"vrtk_bodyphysics","type":"basic","title":"VRTK_BodyPhysics"}
> extends [VRTK_DestinationMarker](doc:vrtk_destinationmarker) ## Overview The body physics script deals with how a user's body in the scene reacts to world physics and how to handle drops. The body physics creates a rigidbody and collider for where the user is standing to allow physics interactions and prevent walking through walls. Upon actually moving in the play area, the rigidbody is set to kinematic to prevent the world from being pushed back in the user's view reducing sickness. The body physics script also deals with snapping a user to the nearest floor if they look over a ledge or walk up stairs then it will move the play area to simulate movement in the scene. To allow for peeking over a ledge and not falling, a fall restiction can happen by keeping a controller over the existing floor and the snap to the nearest floor will not happen until the controllers are also over the floor. ## Inspector Parameters * **Enable Body Collisions:** If checked then the body collider and rigidbody will be used to check for rigidbody collisions. * **Ignore Grabbed Collisions:** If this is checked then any items that are grabbed with the controller will not collide with the body collider. This is very useful if the user is required to grab and wield objects because if the collider was active they would bounce off the collider. * **Headset Y Offset:** The collider which is created for the user is set at a height from the user's headset position. If the collider is required to be lower to allow for room between the play area collider and the headset then this offset value will shorten the height of the generated collider. * **Movement Threshold:** The amount of movement of the headset between the headset's current position and the current standing position to determine if the user is walking in play space and to ignore the body physics collisions if the movement delta is above this threshold. * **Standing History Samples:** The maximum number of samples to collect of headset position before determining if the current standing position within the play space has changed. * **Lean Y Threshold:** The `y` distance between the headset and the object being leaned over, if object being leaned over is taller than this threshold then the current standing position won't be updated. * **Layers To Ignore:** The layers to ignore when raycasting to find floors. * **Fall Restriction:** A check to see if the drop to nearest floor should take place. If the selected restrictor is still over the current floor then the drop to nearest floor will not occur. Works well for being able to lean over ledges and look down. Only works for falling down not teleporting up. * **Gravity Fall Y Threshold:** When the `y` distance between the floor and the headset exceeds this distance and `Enable Body Collisions` is true then the rigidbody gravity will be used instead of teleport to drop to nearest floor. * **Blink Y Threshold:** The `y` distance between the floor and the headset that must change before a fade transition is initiated. If the new user location is at a higher distance than the threshold then the headset blink transition will activate on teleport. If the new user location is within the threshold then no blink transition will happen, which is useful for walking up slopes, meshes and terrains to prevent constant blinking. * **Floor Height Tolerance:** The amount the `y` position needs to change by between the current floor `y` position and the previous floor `y` position before a change in floor height is considered to have occurred. A higher value here will mean that a `Drop To Floor` will be less likely to happen if the `y` of the floor beneath the user hasn't changed as much as the given threshold. ## Class Variables * `public enum FallingRestrictors` - Options for testing if a play space fall is valid * `No_Restriction` - Always drop to nearest floor when the headset is no longer over the current standing object. * `Left_Controller` - Don't drop to nearest floor if the Left Controller is still over the current standing object even if the headset isn't. * `Right_Controller` - Don't drop to nearest floor if the Right Controller is still over the current standing object even if the headset isn't. * `Either_Controller` - Don't drop to nearest floor if Either Controller is still over the current standing object even if the headset isn't. * `Both_Controllers` - Don't drop to nearest floor only if Both Controllers are still over the current standing object even if the headset isn't. ## Class Events * `StartFalling` - Emitted when a fall begins. * `StopFalling` - Emitted when a fall ends. * `StartMoving` - Emitted when movement in the play area begins. * `StopMoving` - Emitted when movement in the play area ends * `StartColliding` - Emitted when the body collider starts colliding with another game object * `StopColliding` - Emitted when the body collider stops colliding with another game object ## Unity Events Adding the `VRTK_BodyPhysics_UnityEvents` component to `VRTK_BodyPhysics` object allows access to `UnityEvents` that will react identically to the Class Events. * `OnStartFalling` - Emits the StartFalling class event. * `OnStopFalling` - Emits the StopFalling class event. * `OnStartMoving` - Emits the StartMoving class event. * `OnStopMoving` - Emits the StopMoving class event. * `OnStartColliding` - Emits the StartColliding class event. * `OnStopColliding` - Emits the StopColliding class event. ## Event Payload * `GameObject target` - The target the event is dealing with. ## Class Methods ### ArePhysicsEnabled/0 > `public bool ArePhysicsEnabled()` * Parameters * _none_ * Returns * `bool` - Returns true if the body physics will interact with other scene physics objects and false if the body physics will ignore other scene physics objects. The ArePhysicsEnabled method determines whether the body physics are set to interact with other scene physics objects. ### ApplyBodyVelocity/3 > `public void ApplyBodyVelocity(Vector3 velocity, bool forcePhysicsOn = false, bool applyMomentum = false)` * Parameters * `Vector3 velocity` - The velocity to apply. * `bool forcePhysicsOn` - If true will toggle the body collision physics back on if enable body collisions is true. * `bool applyMomentum` - If true then the existing momentum of the play area will be applied as a force to the resulting velocity. * Returns * _none_ The ApplyBodyVelocity method applies a given velocity to the rigidbody attached to the body physics. ### ToggleOnGround/1 > `public void ToggleOnGround(bool state)` * Parameters * `bool state` - If true then body physics are set to being on the ground. * Returns * _none_ The ToggleOnGround method sets whether the body is considered on the ground or not. ### TogglePreventSnapToFloor/1 > `public void TogglePreventSnapToFloor(bool state)` * Parameters * `bool state` - If true the the snap to floor mechanic will not execute. * Returns * _none_ The PreventSnapToFloor method sets whether the snap to floor mechanic should be used. ### IsFalling/0 > `public bool IsFalling()` * Parameters * _none_ * Returns * `bool` - Returns true if the body is currently falling via gravity or via teleport. The IsFalling method returns the falling state of the body. ### IsMoving/0 > `public bool IsMoving()` * Parameters * _none_ * Returns * `bool` - Returns true if the user is currently walking around their play area space. The IsMoving method returns the moving within play area state of the body. ### IsLeaning/0 > `public bool IsLeaning()` * Parameters * _none_ * Returns * `bool` - Returns true if the user is considered to be leaning over an object. The IsLeaning method returns the leaning state of the user. ### OnGround/0 > `public bool OnGround()` * Parameters * _none_ * Returns * `bool` - Returns true if the play area is on the ground and false if the play area is in the air. The OnGround method returns whether the user is currently standing on the ground or not. ## Example `VRTK/Examples/017_CameraRig_TouchpadWalking` has a collection of walls and slopes that can be traversed by the user with the touchpad but the user cannot pass through the objects as they are collidable and the rigidbody physics won't allow the intersection to occur.