Glitch in animation

In the video below you can see that when I go on the bridge I have a glitch. My guess is that somehow in that glitch the player is trying to fall here is the code:

if(isGrounded){

    if(Input.GetKey(KeyCode.LeftShift)){
        speed = runSpeed;
    } else if(Input.GetKey(KeyCode.C)){
        speed = croutchSpeed;
        anim.SetFloat("InputMagnitude",1);
    } else {
        speed = walkSpeed;
        anim.SetFloat("InputMagnitude",0);
    }

    float direction = Input.GetAxis("Horizontal") * speed;
    Vector3 movement = new Vector3(direction*Time.deltaTime,0,0);

    player.Translate(movement);

    if(movement.magnitude > 0)
        playerModel.rotation = Quaternion.LookRotation(movement);
   
    anim.SetFloat("InputX", direction);
} else {
    anim.SetFloat("InputX",0);
    anim.SetFloat("InputMagnitude",4);
}

Thank you!

Well yes, the issue seems to be because your player isn’t grounded for a moment. It will probably happens a lot if you keep it that way.

I don’t know what you use to set the IsGrounded bool,but if it depend of a collider, you could make it larger so it won’t set it to false for small variation.

You could also make the falling animation smoother, with a transition betwen the running and the falling, so it wouldn’t look chunky when it happens.

I’m not sure it’s your issue, but it looks like it.

1 Like