Sunday, February 20, 2011

Nobody Likes To Fly In Space - They Want To Drive

There are a lot of arguments out there about how much "fun" realistic space physics are and I am a believer that it's annoying to have to deal with so many ways to maneuver and the concept of the ship pointing one direction while flying another with the engines off!  So, I'd like to share with you how I decided to implement unrealistic but "fun" spaceship flying. Oh, and back in the day I did participate in the making of a game with realistic space physics.


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:
  1. I usually want to be traveling in the direction my spaceship is pointing
  2. 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);

2 comments:

snaip said...

I do prefer realistic physics in space games - combat is another thing. I-WAR2 is a good example of a game which was a lot of fun even with realistic physics.

But personally I don't care too much of fighting in space. Flying without destroying yourself can become very interesting. Ever checked out Rise: The Vieneo Province? It was a pretty cool space sim with realistic physics, and the main focus was on economical development of the game world (actually using the orbit to shorten flight distances between two points on a planet).

Haven't played it for many years since it turned pay to play. I did check the trial out some time ago, unfortunately the game development seems to have ceased long time ago.

Saying that nobody wants to fly in space is silly - certainly I'm a minority, but not nobody. If I want to drive in space, I can play thousands of games like TIE Fighter. If I want to fly in space? I'm stuck to Orbiter.

Robinson said...

Good stuff Alex. Personally I hate realistic physics in space games. It wouldn't be unreasonable to imagine future technology implementing "damping" of some kind in order to make flight models easier.

Quite like the X3 flight model - where you have a set speed and your mouse pointer is the motion vector.