Question by
jackhunter14 · Dec 14, 2020 at 10:17 AM ·
movement2d gamediagonal
Stop diagonal movement 2d top down game
Hello everyone, I am in the process of designing a top down 2d dungeon crawler and I am struggling with stopping my player from moving diagonally. I want it to be so that when I press two keys the first key pressed is the direction that my player moves. Any help would be appreciated.
public float moveSpeed = 5f;
public Rigidbody2D leatherMan;
public Animator animator;
Vector2 movement;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
void FixedUpdate()
{
//movement
leatherMan.MovePosition(leatherMan.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
Comment