- Home /
How would I get a button press to override/combine with currently held buttons?
Basically I'm making a movement script and I want to be able to switch between movements by switching which buttons I'm holding. So, if you were holding left you would move left, and if you then started holding up too, you would start moving diagonally up and to the left. If you then let go of left you would start moving up. So far the closest I can get to this is pressing both up and left at the same time to go diagonally (for some reason this only seems to work when I use the hold interaction and I would prefer it on the press interaction). Does anyone know how I would go about doing this?
Answer by richatd_q · Jul 28, 2020 at 07:33 PM
Ok, so I figured it out and apparently it was the fact that I was using the press and release interaction. When I did it with no interactions, it gave me the result I wanted.
Answer by xxmariofer · Jul 28, 2020 at 07:22 AM
simply use the Input.GetKey method
Vector3 direction = Vector3.Zero;
if (Input.GetKey(KeyCode.A))
{
direction += new Vector3(0,0,-1);
}
if (Input.GetKey(KeyCode.W))
{
direction += new Vector3(0,0,1);
}
if (Input.GetKey(KeyCode.D))
{
direction += new Vector3(1,0,0);
}
if (Input.GetKey(KeyCode.S))
{
direction += new Vector3(-1,0,0);
}
Sorry, I should have specified. I meant for the new input system.