Class GravityProvider
Locomotion provider that provides gravity to the player.
This provider will also check if the player is grounded using a sphere cast from the player's head.
Gravity will be applied to the player anytime use
Inherited Members
Namespace: UnityEngine .XR.Interaction.Toolkit.Locomotion.Gravity
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
[AddComponentMenu("XR/Locomotion/Gravity Provider", 11)]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@3.1/api/UnityEngine.XR.Interaction.Toolkit.Locomotion.Gravity.GravityProvider.html")]
[DefaultExecutionOrder(-207)]
public class GravityProvider : LocomotionProvider
Properties
gravityAccelerationModifier
Determines the speed at which a player reaches max gravity velocity.
Declaration
public float gravityAccelerationModifier { get; set; }
Property Value
Type | Description |
---|---|
float |
gravityControllers
(Read Only) The gravity controllers that can pause gravity.
Declaration
public List<IGravityController> gravityControllers { get; }
Property Value
Type | Description |
---|---|
List<IGravity |
Remarks
Automatically populated during Awake() with all components under the Locomotion
isGrounded
If the player is on the ground.
Declaration
public bool isGrounded { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
onGravityLockChanged
Event that is called when gravity lock is changed.
Declaration
public UnityEvent<GravityOverride> onGravityLockChanged { get; set; }
Property Value
Type | Description |
---|---|
Unity |
onGroundedChanged
Callback for anytime the grounded state changes.
Declaration
public UnityEvent<bool> onGroundedChanged { get; }
Property Value
Type | Description |
---|---|
Unity |
See Also
sphereCastDistanceBuffer
Buffer for the distance of the sphere cast used to check if the player is grounded.
Declaration
public float sphereCastDistanceBuffer { get; set; }
Property Value
Type | Description |
---|---|
float |
sphereCastLayerMask
The layer mask used for the sphere cast to check if the player is grounded.
Declaration
public LayerMask sphereCastLayerMask { get; set; }
Property Value
Type | Description |
---|---|
Layer |
sphereCastRadius
Buffer for the radius of the sphere cast used to check if the player is grounded.
Declaration
public float sphereCastRadius { get; set; }
Property Value
Type | Description |
---|---|
float |
sphereCastTriggerInteraction
Whether trigger colliders are considered when using a sphere cast to determine if grounded.
Declaration
public QueryTriggerInteraction sphereCastTriggerInteraction { get; set; }
Property Value
Type | Description |
---|---|
Query |
Remarks
When set to Use
terminalVelocity
Determines the maximum fall speed based on units per second.
Declaration
public float terminalVelocity { get; set; }
Property Value
Type | Description |
---|---|
float |
transformation
The transformation that is used by this component to apply translation movement.
Declaration
public XROriginMovement transformation { get; set; }
Property Value
Type | Description |
---|---|
XROrigin |
updateCharacterControllerCenterEachFrame
Sets the center of the character controller to match the local x and z positions of the player camera.
Declaration
public bool updateCharacterControllerCenterEachFrame { get; set; }
Property Value
Type | Description |
---|---|
bool |
useGravity
Apply gravity to the XR Origin.
Declaration
public bool useGravity { get; set; }
Property Value
Type | Description |
---|---|
bool |
useLocalSpaceGravity
Apply gravity based on the current Up vector of the XR Origin.
Declaration
public bool useLocalSpaceGravity { get; set; }
Property Value
Type | Description |
---|---|
bool |
Methods
Awake()
See Mono
Declaration
protected override void Awake()
Overrides
GetCurrentUp()
Gets the current up direction based on use
Declaration
public Vector3 GetCurrentUp()
Returns
Type | Description |
---|---|
Vector3 | Returns |
IsGravityBlocked()
Checks if gravity is blocked by any of the following conditions:
- If gravity is not being used.
- If the player is grounded.
- If any provider is forcing gravity off.
- If any provider is pausing gravity while no provider is forcing gravity on.
Declaration
public bool IsGravityBlocked()
Returns
OnDrawGizmosSelected()
Unity calls this when drawing gizmos while the object is selected.
Declaration
protected void OnDrawGizmosSelected()
ResetFallForce()
Resets the fall force to zero.
Declaration
public void ResetFallForce()
Start()
Declaration
protected virtual void Start()
TryLockGravity(IGravityController, GravityOverride)
Locks gravity for the provider based on gravityOverride
.
Declaration
public bool TryLockGravity(IGravityController provider, GravityOverride gravityOverride)
Parameters
Type | Name | Description |
---|---|---|
IGravity |
provider | The |
Gravity |
gravityOverride | Determines the type of lock used. |
Returns
Remarks
This adds the provider to the internal lists keeping track of the locomotion providers that have forced gravity on or off.
See Also
TryProcessGravity(float)
Updates current fall velocity if gravity is not currently blocked.
Declaration
protected virtual bool TryProcessGravity(float time)
Parameters
Returns
Type | Description |
---|---|
bool | Returns true if Is |
UnlockGravity(IGravityController)
Unlock gravity for the provider.
Declaration
public void UnlockGravity(IGravityController provider)
Parameters
Type | Name | Description |
---|---|---|
IGravity |
provider | The provider to unlock. |
Remarks
Removes the provider from the internal lists keeping track of the locomotion providers that have forced gravity on or off.
See Also
Update()
Declaration
protected virtual void Update()