I'm trying to create a 2D space shooter with controls similar to the classic arcade game Asteroids. The controls involve a thrust button which propels the player in whatever direction they are facing, and left/right rotation controls which changes the player's angle. I plan to build on of this basic scheme and perhaps include mouse control for direction, multiple thrust directions, etc. But first I want to have the core mechanic down in a way that will be easy to build on.
My thoughts are storing the data for position and movement as follows:
Position - X,Y co-ordinates
Speed - simple scaler variable from 0 to some MaxSpeed value
Angle - float variable in radians
Direction vector - X,Y movement vector between -1 and 1
For the movement algorithm, when the player presses the thrust button, the speed value will increase and the direction vectors will be calculated based on the player angle. During the player update phase, the players position will be incremented along the X and Y axis by multiplying the direction vectors by the speed value.
What I'm not sure how to incorporate is momentum. Ideally, I want the player to keep moving after the thrust button is released. I also don't want the player to immediately change direction when they initiate a thrust in a different angle.
Any thoughts on how to approach this?
edited to add: Thinking about this a bit, I wonder if having two direction vectors would work. Have one for the existing movement direction, and then if the player changes direction, create a new "target" direction vector. Then simply increment/decrement the direction vector over time until it matches the "target" vector.