Search Unity

Bug Animation works great when i walk but when i sprint or stand still it is bugged

Discussion in 'Animation' started by Deagarys, Oct 10, 2022.

  1. Deagarys

    Deagarys

    Joined:
    Mar 20, 2019
    Posts:
    2


    When the character is walking all the jumping animations work correctly. But when I stand still or run the third jump animation and the second one becomes bugged. I have no idea what the issue is...

    I tried using different animations but also caused the same bug. I also tried changing the walking and running speeds but did not have different results. Does anyone have any idea?

    The logic behind my jump:

    void SetupJumpVariables()
    {
    float timeToApex = _maxJumpTime / 2;
    _gravity = (-2 * _maxJumpHeight) / Mathf.Pow(timeToApex, 2);
    _initialJumpVelocity = (2 * _maxJumpHeight) / timeToApex;

    float secondJumpGravity = (-2 * (_maxJumpHeight + 2)) / Mathf.Pow((timeToApex * 1.25f), 2);
    float secondJumpInitialVelocity = (2 * (_maxJumpHeight + 2)) / (timeToApex * 1.25f);

    float thirdJumpGravity = (-2 * (_maxJumpHeight + 4)) / Mathf.Pow((timeToApex * 1.5f), 2);
    float thirdJumpInitialVelocity = (2 * (_maxJumpHeight + 4)) / (timeToApex * 1.5f);

    _initialJumpVelocities.Add(1, _initialJumpVelocity);
    _initialJumpVelocities.Add(2, secondJumpInitialVelocity);
    _initialJumpVelocities.Add(3, thirdJumpInitialVelocity);

    _jumpGravities.Add(0, _gravity);
    _jumpGravities.Add(1, _gravity);
    _jumpGravities.Add(2, secondJumpGravity);
    _jumpGravities.Add(3, thirdJumpGravity);
    }


    I use a state machine so the jump itself and the jumping animation triggers is handled in the jump state as such:

    void HandleJump()
    {
    if (Ctx.JumpCount < 3 && Ctx.CurrentJumpResetRoutine != null)
    {
    Ctx.StopCoroutine(Ctx.CurrentJumpResetRoutine);
    }
    Ctx.Animator.SetBool(Ctx.IsJumpingHash, true);
    Ctx.RequireNewJumpPress = true;
    Ctx.IsJumping = true;
    Ctx.JumpCount += 1;
    Ctx.Animator.SetInteger(Ctx.JumpCountHash, Ctx.JumpCount);

    Ctx.CurrentMovementY = Ctx.InitialJumpVelocities[Ctx.JumpCount];
    Ctx.AppliedMovementY = Ctx.InitialJumpVelocities[Ctx.JumpCount];
    }
     
    Last edited: Oct 10, 2022