Hey guys, I started learning Unity recently and I am facing a problem. I can’t seem to fix the jump animation with the body. If I apply force and play the animation, it would seem as if the character jumped twice the height, while actually the body jumped normally.
The walk animation was easy, because it was in-place. How do I fix this?
void Update () {
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
float translation = vertical * walkSpeed;
float rotation = horizontal * rotationSpeed;
translation *= Time.deltaTime;
rotationSpeed *= Time.deltaTime;
transform.Translate(0, 0, translation);
transform.Rotate(0, rotation, 0);
//on ground
if (IsGrounded() && Input.GetButtonDown("Jump"))
{
animator.SetTrigger("jump");
rbody.AddForce(Vector3.up * 1.0f * rbody.mass * 10, ForceMode.Impulse);
}
else if (IsGrounded() && translation > 0 && !Input.GetButtonDown("Jump"))
{
animator.SetBool("walking", true);
animator.SetBool("walkingBack", false);
animator.SetBool("idle", false);
}
else if(IsGrounded() && translation < 0 && !Input.GetButtonDown("Jump"))
{
animator.SetBool("walkingBack", true);
animator.SetBool("walking", false);
animator.SetBool("idle", false);
}
else
{
animator.SetBool("walkingBack", false);
animator.SetBool("walking", false);
animator.SetBool("idle", true);
Repositioning();
}
Rotating(horizontal, vertical);
}