Creating Increased Movement Speed With GetKeyDown

Adam Reed
2 min readApr 22, 2021

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.

[Bonus Tip]

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.

--

--

Adam Reed

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!