I want to make my player move only using “WASD” , so I have this script:
void FixedUpdate()
{
//float moveHorizontal = Input.GetAxis("Horizontal");
//float moveVertical = Input.GetAxis("Vertical");
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S))
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
}
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
}
}
The player moves when I hit “WASD” but when I, say, I hit “W”, it’ll just keep moving forward itself even after I realeased the key. I’m not talking about the " GetAxis " soomthing effect here, I’m saying the player will move at the same speed on its own forward…
Please help! Thanks in advance!