Instead of manipulating the velocity directly, add another variable: acceleration, that gradually, smoothly alters the velocity:
From classical physics (Newton's laws of motion):
a = F/m // a Force will result in a smaller acceleration on objects with more mass
v += a // acceleration is the rate of change in velocity
p += v // velocity is the rate of change in position
where:
a = acceleration, v = velocity, p = position
F = force, m = mass
(Note m is the only scalar value; F, a, v, and p are all 2D or 3D vectors)
Also, there are actually two directions:
- The direction the ship is facing. Force from engines is applied along this vector.
- The direction the ship is actually moving (due to momentum). This is the velocity vector v.
I answered a related question on StackOverflow: 2D Spaceship movement math. There is some sample code in that answer.
Also you can check out my asteroids demo, which implements the algorithm described above.