So I’ve been making a new game from scratch, my second ever project. It’s a top-down shooter, and I’ve starting working on the movement of the character but I keep finding it’s not working as well as I thought it would. I’m making it by using if statements and velocity like this.
void Update()
{
if (Input.GetKey(KeyCode.W))
{
playerVelo.y = upwardSpeed;
myBody.velocity = playerVelo;
Debug.Log("Up");
}
if (Input.GetKey(KeyCode.D))
{
playerVelo.x = sideWaySpeed;
myBody.velocity = playerVelo;
Debug.Log("Right");
}
if (!Input.anyKey)
{
playerVelo = new Vector2(0,0);
myBody.velocity = playerVelo;
Debug.Log("NothingPressed");
}
}
But the code has a weird property were if I stop pressing say the D key it should just go up but it doesn’t it keep moving right and up until I stop pressing every button is there any way I can check only if one button goes up, I keep looking it up but I really can’t find anything.