This state Inherits from the base Jump State and allows the jump button to be held down to jump higher.
State
It simply applies some additional upwards acceleration to the character during each frame of the animation before the character returns to their Idle state (most likely to Fall since they should be in the air). The HoldJumpState
script itself is basically self-explanatory:
public class HoldJumpState : JumpState
{
[SerializeField, MetersPerSecondPerSecond(Rule = Value.IsNotNegative)]
[Tooltip("The continuous acceleration applied while holding the jump button")]
private float _HoldAcceleration = 40;
public float HoldAcceleration => _HoldAcceleration;
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
PlatformerUtilities.NotNegative(ref _HoldAcceleration);
}
#endif
protected virtual void FixedUpdate()
{
Character.Body.Velocity += new Vector2(0, _HoldAcceleration * Time.deltaTime);
}
}
The ability to short jump by releasing the jump button quickly is handled by the Player Brain simply returning the character to their Idle State early so that this FixedUpdate
stops applying the additional acceleration.