I want my game object to move from A to B. But when I press a key it only moves a bit and I have to keep pressing it a hundred times to keep making it move to point B. How can I fix this problem without applying physics?
My lovely script.
3043949–228125–moveSlowly.cs (507 Bytes)
Look at the docs and check into the difference between:
Input.GetKeyDown();
and
Input.GetKey();
If you’re making an arcade-game-like motion, the latter is what you want. One is continuous, one is edge-trigger.
Thank you for your reply. I have done that. But the object doesn’t move all the way to his target. I will look at the docs more thoroughly.
If you use .GetKeyDown(), the contents of the if block are only going to be executed on the one single frame that the button goes down and never again, until the button goes up, then back down again.
If you use .GetKey() then it will execute on every single continuous frame that the button is held down. I suspect this is more what you want if you want arcade game like controls.
In this case you want a coroutine, since the action of moving is an all-or-nothing proposition: QBert cannot stop mid-stride, but he takes X amount of time to go from point A to point B, so perfect use of a coroutine. You would start the coroutine when input is received, and lock out further input until you arrive at the destination, then re-enable new input.