Friction for Smooth Movement

One of my self challenges for 2015 is to create 1 game a month starting in February. So I decided to start with a classic type of arcade game, a scrolling shooter.

The first implementation of the game only moved when the player was using input to control the ship. As soon as the player let off the key or stopped touching the screen, the ship would stop. This did not feel natural at all. In order to give the game a smooth and more natural feel, I decided to introduce a friction factor so that the player is slowed down a little until coming to a complete stop. Like this

If velocity in x direction >= friction
velocity is reduced by friction amount
If velocity in x direction < friction velocity is 0 Same for the y direction. You may need to play around with what the friction value is to determine what feels natural. Also, the frame rate that you choose for your game will affect what this value is. Note: you may need to account for both positive and negative velocities, depending on how you implement movement in your game.

I Want to Be a Better Developer