docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    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 useGravity is true and isGrounded is false. See IGravityController for external control over gravity.

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    LocomotionProvider
    GravityProvider
    Inherited Members
    LocomotionProvider.mediator
    LocomotionProvider.transformationPriority
    LocomotionProvider.locomotionState
    LocomotionProvider.isLocomotionActive
    LocomotionProvider.canStartMoving
    LocomotionProvider.locomotionStateChanged
    LocomotionProvider.locomotionStarted
    LocomotionProvider.locomotionEnded
    LocomotionProvider.beforeStepLocomotion
    LocomotionProvider.afterStepLocomotion
    LocomotionProvider.TryPrepareLocomotion()
    LocomotionProvider.TryStartLocomotionImmediately()
    LocomotionProvider.TryEndLocomotion()
    LocomotionProvider.OnLocomotionStarting()
    LocomotionProvider.OnLocomotionEnding()
    LocomotionProvider.OnLocomotionStateChanging(LocomotionState)
    LocomotionProvider.TryQueueTransformation(IXRBodyTransformation)
    LocomotionProvider.TryQueueTransformation(IXRBodyTransformation, int)
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(string)
    Component.SendMessageUpwards(string, object, SendMessageOptions)
    Component.SendMessageUpwards(string, object)
    Component.SendMessageUpwards(string)
    Component.SendMessageUpwards(string, SendMessageOptions)
    Component.SendMessage(string, object)
    Component.SendMessage(string)
    Component.SendMessage(string, object, SendMessageOptions)
    Component.SendMessage(string, SendMessageOptions)
    Component.BroadcastMessage(string, object, SendMessageOptions)
    Component.BroadcastMessage(string, object)
    Component.BroadcastMessage(string)
    Component.BroadcastMessage(string, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    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.2/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<IGravityController>
    Remarks

    Automatically populated during Awake() with all components under the LocomotionMediator that implement the interface.

    isGrounded

    If the player is on the ground.

    Declaration
    public bool isGrounded { get; }
    Property Value
    Type Description
    bool
    See Also
    onGroundedChanged

    onGravityLockChanged

    Event that is called when gravity lock is changed.

    Declaration
    public UnityEvent<GravityOverride> onGravityLockChanged { get; set; }
    Property Value
    Type Description
    UnityEvent<GravityOverride>

    onGroundedChanged

    Callback for anytime the grounded state changes.

    Declaration
    public UnityEvent<bool> onGroundedChanged { get; }
    Property Value
    Type Description
    UnityEvent<bool>
    See Also
    isGrounded

    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
    LayerMask

    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
    QueryTriggerInteraction
    Remarks

    When set to UseGlobal, the value of Queries Hit Triggers (queriesHitTriggers) in Edit > Project Settings > Physics will be used.

    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
    XROriginMovement

    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 MonoBehaviour.

    Declaration
    protected override void Awake()
    Overrides
    LocomotionProvider.Awake()

    GetCurrentUp()

    Gets the current up direction based on useLocalSpaceGravity. This value is normalized.

    Declaration
    public Vector3 GetCurrentUp()
    Returns
    Type Description
    Vector3

    Returns -Physics.gravity.normalized or the up of the XR Origin.

    IsGravityBlocked()

    Checks if gravity is blocked by any of the following conditions:

    1. If gravity is not being used.
    2. If the player is grounded.
    3. If any provider is forcing gravity off.
    4. If any provider is pausing gravity while no provider is forcing gravity on.
    Declaration
    public bool IsGravityBlocked()
    Returns
    Type Description
    bool

    Returns true if gravity is blocked for any reason.

    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()

    MonoBehaviour

    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
    IGravityController provider

    The provider requesting the lock.

    GravityOverride gravityOverride

    Determines the type of lock used.

    Returns
    Type Description
    bool

    Returns true if the provider is not already being locked.

    Remarks

    This adds the provider to the internal lists keeping track of the locomotion providers that have forced gravity on or off.

    See Also
    UnlockGravity(IGravityController)

    TryProcessGravity(float)

    Updates current fall velocity if gravity is not currently blocked.

    Declaration
    protected virtual bool TryProcessGravity(float time)
    Parameters
    Type Name Description
    float time

    By default, this uses deltaTime as it's called from Update().

    Returns
    Type Description
    bool

    Returns true if IsGravityBlocked() is false.

    UnlockGravity(IGravityController)

    Unlock gravity for the provider.

    Declaration
    public void UnlockGravity(IGravityController provider)
    Parameters
    Type Name Description
    IGravityController 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
    TryLockGravity(IGravityController, GravityOverride)

    Update()

    MonoBehaviour

    Declaration
    protected virtual void Update()
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)