How do I make my character not move when pressing both positive and negative horizontal buttons?

This is the code that I use for my players movement:

GetComponent<Rigidbody2D>().velocity = new Vector2(Input.GetAxis("Horizontal") * speed, Input.GetAxis("Vertical") * speed);

So if someone could help me then that would be great!

Could always change the Input Manager to separate keys and subtract them from eachother.

1 Like

I tried but I did not really know how you could do it, I am really new to unity.

You can go to Edit>Project Settings>Input Manager and customize your controls. What I suggested is creating two controls for reach axis, positive and negative. Then, you would read the input for each separately, and if they’re both pressed, they would cancel out.

I am so confused, I have no idea of how to do these things!