|Cassini Division 2004|
To start with lets consider that most games use some kind of physics engine and those deal in forces primarily so we need to make each of the engines apply forces to the spaceship. But we can't stop there because that is the realistic way and controlling a for-real spaceship can be so challenging that you don't have much time to deal with anything else like, say, shooting. I mean, just think about all the controls you have to have in your ship to make your ship rotate in any direction and move in any direction! Now, I have considered a game where each spaceship has a pilot and a separate player as the gunner, but lets not get distracted...
The easiest way to fly in space besides autopilot is to make it like driving - something that most people are used to. You see, I want two things when I'm driving:
- I usually want to be traveling in the direction my spaceship is pointing
- When I hit the gas I want the spaceship to move, and when I let go I want it to come to a stop.
Handling the first issue is simple after you handle the second issue, just make the back engine the biggest and don't go putting big engines on the sides or front. The second issue is not too difficult either - apply dampening to the spaceship so that it acts more like it is moving through liquid/air than through a vacuum.
By applying the dampening we ruin realistic space physics, but make spaceships easier to control. Now since the ship is really moving through some kind of liquid/air it takes constant force to keep it moving and we now have an excuse for a fuel gauge and as an added bonus, when the spaceship enters the atmosphere or ocean we can use the same controls just fiddle with the amount of dampening.
Last thing I'd like to mention is the issue of 'max speed'. When we have dampening then the 'max speed' of a spaceship makes more sense and we have the excuse for putting spaceships in the game with more powerful engines - where with realistic space games you can fly incredibly fast in a tin can with the help of some gravity, you just can't start or stop fast.
Oh, and collisions should work with our physics plus dampening model too and keep all that space debris from moving off into infinity where nobody could tell that it was once part of a destroyed spaceship.
On a more practical note, here is how I implemented the above physics model in OGE with Bullet.
1. Use btRigidBody::setDampening() to set the dampening on the Bullet rigid body object
2. Use Bullet's internal tick callback to apply constant forces before the dampening is applied:
btRigidBody->applyCentralImpulse(velocity * deltaTime);
btRigidBody->applyTorqueImpulse(angular * deltaTime);