Ship doesn't move when I keep arrow buttons pressed down

My ship moves left and right just right when I press the left and arrow buttons, but if I want it to move faster and log time*deltaTime by pressing and holding the arrow buttons, it won’t move any faster. I’m just wondering why do I have to keep clicking the left and right arrows the make the ship move, I think it would be more practical to be able to hold it down to make the ship move in either direction.

You should have something like this placed in the Update method of your PlayerController.cs

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.position += Vector3.left * m_ShipSpeed * Time.deltaTime;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.position += Vector3.right * m_ShipSpeed * Time.deltaTime;
        }

I have that on the code, it still doesn’t move the ship while pressing the arrow keys down, I have to keep clicking the arrow keys to make the ship move in either direction. Could it be a keyboard design issue? I am using an ASUS ROG laptop.

Are you using Input.GetKey or Input.GetKeyDown?

Input.GetKeyDown will only return true on the frame that you pressed it down, so it will not continue to move when you hold the key down.

Oh!, this does fix it. I guess I got confused with understanding “Down” as pressing it down…
Thank You!

Glad it helped! I think I definitely have had that problem at some point - it’s easy to mix them up

Privacy & Terms