Creating Increased Movement Speed With GetKeyDown
As an extra bonus, in my next few articles, I’ll be showing you all some simple features that you can add to your game with little to no effort at all!
To start I’m going to add a feature to my Space Shooter game that allows the player to hold the “Left Shift” key to increase their movement speed. This same logic can be used in a variety of different games to allow for something akin to “Sprinting”.
The code itself is very simple…
GetKeyDown is called when the specified key is initially pressed.
GetKeyUp is called when the specified key is eventually released.
By simply multiplying and dividing your speed variable by the same number you allow your player to speed up and slow down in accordance with the key presses.
Now if you were to implement that for a game that involves a character running animation, you will just need to accommodate the run animation’s playback speed to accommodate the increased player movement speed.