Class JumpProvider
Jump Provider allows the player to jump in the scene. This uses a jump force to drive the value of the jumpHeight over time to allow the player to control how floaty the jump feels. The player can hold down the jump button to increase the altitude of the jump. This provider handles coyote time to allow jumping to feel more consistent.
Implements
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.Locomotion.Jump
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
[AddComponentMenu("XR/Locomotion/Jump Provider", 11)]
[HelpURL("https://docs.unity.cn/Packages/com.unity.xr.interaction.toolkit@3.2/api/UnityEngine.XR.Interaction.Toolkit.Locomotion.Jump.JumpProvider.html")]
public class JumpProvider : LocomotionProvider, IGravityController
Properties
canProcess
Whether the gravity can be processed. Gravity controllers that can process receive queries to gravityPaused, controllers that cannot process do not.
Declaration
public bool canProcess { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
It's recommended to return isActiveAndEnabled when implementing this interface in a MonoBehaviour.
disableGravityDuringJump
Disable gravity during the jump. This will result in a more floaty jump.
Declaration
public bool disableGravityDuringJump { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
earlyOutDecelerationSpeed
The speed at which the jump will decelerate when the player releases the jump button early.
Declaration
public float earlyOutDecelerationSpeed { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
gravityPaused
Whether gravity is paused.
Declaration
public bool gravityPaused { get; protected set; }
Property Value
| Type | Description |
|---|---|
| bool |
See Also
inAirJumpCount
The number of times a player can jump before landing.
Declaration
public int inAirJumpCount { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
isJumping
Returns whether the player is currently jumping.
Declaration
public bool isJumping { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
jumpForgivenessWindow
The time window after leaving the ground that a jump can still be performed. Sometimes known as coyote time.
Declaration
public float jumpForgivenessWindow { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
jumpHeight
The height (approximately in meters) the player will be when reaching the apex of the jump.
Declaration
public float jumpHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
jumpInput
Input data that will be used to perform a jump. If the source is an Input Action, it must have a button-like interaction where phase equals performed when pressed. Typically a UnityEngine.InputSystem.Controls.ButtonControl Control or a Value type action with a Press interaction.
Declaration
public XRInputButtonReader jumpInput { get; set; }
Property Value
| Type | Description |
|---|---|
| XRInputButtonReader |
maxJumpHoldTime
The maximum time a player can hold down the jump button to increase altitude.
Declaration
public float maxJumpHoldTime { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
minJumpHoldTime
The minimum amount of time the jump will execute for.
Declaration
public float minJumpHoldTime { 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 |
unlimitedInAirJumps
Allow player to jump without being grounded.
Declaration
public bool unlimitedInAirJumps { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
variableHeightJump
Whether the jump height is based on how long the player continues to hold the jump button. Enable to allow the player to stop their jump early when input is released before reaching the maximum jump height. Disable to jump a fixed height.
Declaration
public bool variableHeightJump { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
Awake()
See MonoBehaviour.
Declaration
protected override void Awake()
Overrides
CanJump()
Determines if the player can jump.
Declaration
public bool CanJump()
Returns
| Type | Description |
|---|---|
| bool | Returns whether the player can jump. The Jump() method will not do anything while this method returns false. |
Remarks
Returns true when any of these conditions are met:
- The player is grounded or within the jump forgiveness time (coyote time).
- The player has remaining in-air jumps.
See Also
IsPausingGravity()
Whether this JumpProvider is currently pausing gravity.
Declaration
public bool IsPausingGravity()
Returns
| Type | Description |
|---|---|
| bool | Returns true if isJumping and disableGravityDuringJump are currently true, otherwise returns false. |
Jump()
Initiates the jump routine.
Declaration
public void Jump()
See Also
OnDisable()
See MonoBehaviour.
Declaration
protected virtual void OnDisable()
OnEnable()
See MonoBehaviour.
Declaration
protected virtual void OnEnable()
OnGravityLockChanged(GravityOverride)
Called from TryLockGravity(IGravityController, GravityOverride) when gravity lock is changed.
Declaration
protected virtual void OnGravityLockChanged(GravityOverride gravityOverride)
Parameters
| Type | Name | Description |
|---|---|---|
| GravityOverride | gravityOverride | The GravityOverride to apply. |
See Also
OnGroundedChanged(bool)
Called from GravityProvider when the grounded state changes.
Declaration
protected virtual void OnGroundedChanged(bool isGrounded)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isGrounded | Whether the player is on the ground. |
See Also
OnValidate()
See MonoBehaviour.
Declaration
protected virtual void OnValidate()
RemoveGravityLock()
Removes this provider from the GravityProvider list's of locked providers.
Declaration
public void RemoveGravityLock()
TryLockGravity(GravityOverride)
Attempts to lock gravity.
Declaration
public bool TryLockGravity(GravityOverride gravityOverride)
Parameters
| Type | Name | Description |
|---|---|---|
| GravityOverride | gravityOverride | The GravityOverride to apply. |
Returns
| Type | Description |
|---|---|
| bool | Whether the gravity was successfully locked. |
Update()
See MonoBehaviour
Declaration
protected virtual void Update()