[Top down shooter] lock the diagonal movement

Hi everybody !

I’m doing a 2D on android and i want to use a joystick to move my player in 4 direction.

but whith my code, my player can move to 8 direction
So i want to know if i can lock the diagonal direction?

Here my code :slight_smile:

 if (CrossPlatformInputManager.GetAxis("Horizontal") > 0.5)
            {
                // vector2 move code right

            }

            if (CrossPlatformInputManager.GetAxis("Horizontal") < -0.5)
            {
          
  // vector2 move code left

            }

            if (CrossPlatformInputManager.GetAxis("Vertical") < -0.5)
            {
          
  // vector2 move code down

            }

            if (CrossPlatformInputManager.GetAxis("Vertical") > 0.5)
            {
          
  // vector2 move code up

            }

Thanks for reading me !
Have a good day !:slight_smile:

an easy way to make each direction exclusive would be to make those ‘else if’ statements