Jumping not working correctly

public class PlayerJumpingState : PlayerBaseState
{
    public PlayerJumpingState(PlayerStateMachine stateMachine) : base(stateMachine) { }

    private readonly int JumpHash = Animator.StringToHash("Jump_Apex");

    private Vector3 momentum;

    private const float CrossFadeDuration = 0.1f;

    public override void Enter()
    {
        stateMachine._forceReceiver.Jump(stateMachine.JumpForce);

        momentum = stateMachine._characterController.velocity;
        momentum.y = 0f;

        stateMachine._animator.CrossFadeInFixedTime(JumpHash, CrossFadeDuration);
    }

    public override void Tick(float deltaTime)
    {
        Move(momentum, deltaTime);

        if (stateMachine._characterController.velocity.y <= 0)
        {
            stateMachine.SwitchState(new PlayerFallingState(stateMachine));
            return;
        }

        FaceTarget();
    }

    public override void Exit()
    {

    }
}
1 Like

Hi Masuta.

So far, the code looks correct. What is happening when you jump?

Privacy & Terms