Im trying to make a movement code that when you move horizontally you can’t go vertically with my vertically code and vice-versa. can someone help me please
Assuming your character has a rigidbody, you can do something like:
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
//We are not currently moving on the x axis
if (rb.velocity.x != 0) {
moveVertical = 0;
}
//We are not currently moving on the y axis
else if (rb.velocity.y != 0) {
moveHorizontal = 0;
}
Vector3 Movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce(Movement);
}
Or if you move in some other way just set movingX and movingY booleans so that only the part of code on the correct axis is executed