I am new to 2D game development.
I've made several games, but they've made almost no use of physics. Now I want to try making a game that uses some basic physics to look more realistic.
The game involves spaceships battling in space. I'm ignoring gravity. Each spaceship can move up, down, left, right or any of the 4 diagonals.
I want each spaceship to accelerate when moved (up to some threshold speed) and gradually slow to a stop otherwise.
I'm planning to give each spaceship a velocity
and acceleration
attribute.
The acceleration
is set to some constant value. For example, 5.
When the spaceship starts moving, the velocity
is set to some initial value. Then every period of time as long as it should be moving (for example every 30 milliseconds), the acceleration
value is added to it.
When the user stops moving the ship, the reverse process happens: the acceleration
value is decreased from velocity
until velocity equals 0.
I have two questions regarding this:
Is this general type of physics realistic and/or common in games? Is this the right direction? Am I forgetting some factor or anything to be considered?
Regarding the specific implementation I'm planning: Is the right way to accelerate is add a constant value to the speed of the object? Or do I need to gradually increase the value added to the speed, thus increasing the acceleration?