Hello, I’m trying to move a player with an animation that makes him jump forward.
The problem is when I press the key to run the animation, the player goes forward and then, when the animation ends, the player goes back to the start point.
I know the solution is to move the player position when the animation runs, but the problem is that I can’t do it because in FixedUpdate I get the position through Input.GetAxis().
static Animator anim;
private float Speed = 2.0f;
public float rotationSpeed = 150.0f;
public float WalkSpeed = 2.0f;
public float RunSpeed = 4.0f;
void Start () {
anim = GetComponent<Animator>();
}
void FixedUpdate () {
float translation = Input.GetAxis("Vertical") * Speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
translation *= Time.deltaTime;
rotation *= Time.deltaTime;
transform.Translate(0, 0, translation);
transform.Rotate(0, rotation, 0);
if (Input.GetMouseButtonDown(0))
{
anim.SetBool("isIdle", false);
anim.SetBool("isTurning", false);
anim.SetBool("isWalking", false);
anim.SetBool("isRunning", false);
anim.SetTrigger("attack");
}
}