Ok so I’m making a 2D top down shooter game following a tutorial by Couch Ferret. When I press only press one direction, the character stays facing that direction when I let go. However when I press two buttons at once, like right and up, to move diagonally and then let go, the character faces one of the two directions but not diagonally. I guess this is because I am not letting go of both directions at exactly the same time but I still want the character to face diagonally even if I don’t let go of the buttons at exactly the same time (maybe like a 0.5 second window). But I don’t know how to do do it as I am still new to coding.
Anyways here is my code:
public Rigidbody2D rb;
public float speed;
public Animator animator;
public Vector2 movement;
void Update()
{
movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
rb.velocity = Vector2.ClampMagnitude(movement, 1.0f) * speed;
if (movement != Vector2.zero)
{
animator.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
animator.SetFloat("Vertical", Input.GetAxis("Vertical"));
}
}
Thanks in advance for anyone who helps.