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);

Tuesday, January 4, 2011

A New Year With New Goals?

The end of last year was somewhat unproductive for me on the planet front.  I was looking back at my calendar today and see that I spent most of my time doing real life work and being a dad.  I also spent a lot of free time playing games too instead of making them.

The two things I did work on that were planet related were OGE and Spacescape.  I made the developer list for OGE, and I might be the only active developer for now, but I hope that changes soon.  I spent most of my OGE developer time working on the RakNet networking and Bullet physics systems and have been trying to get a minimal networking example working with a small player controlled spaceship, some exploding mines and a planet.  Let's just say that networking + physics debugging can be annoying and I had no idea that making a spaceship NOT have Newtonian physics in space would be so challenging! - more on that later, maybe.

Spacescape got some bug fixes and minor features and I added the CMake build system to ease the pain for new developers and for me each time I develop on a new machine, especially one with a different OS like OSX. I also got my first and only Spacescape donation woohoo! and a bunch of feature requests, support requests and compliments.


On the table for this year are:
- Finish the OGE networking space example
- Re-asses and tackle placing objects on planets (vegetation, buildings, players etc)
- Fix planet underwater shaders
- Add simple clouds to planets
- Make the networking space example into a small game
- Release the planet plugin source
- Port Spacescape to OSX
- Divide Spacescape into "basic" and "advanced" modes so it is loads easier to use for the casual user.

Other possibilities include:
- Use acko.net method for computing planet normal maps
- Figure out additional light maps so we can have lights on the dark side of the planet
- Re-asses how distance/scale is handled when approaching the limits.
- Form a team of like-minded individuals

Hope you have a great start to the new year!

Wednesday, June 30, 2010

Planet Water Shader Tests & OGE

First of all, I haven't posted in a while because I've been sick, then I got my new dev machine and was busy setting it up and playing games on it and other real life stuff.

So, water for this small planet has been difficult for me and I've tried a couple approaches and have yet to get something I like.

What I want:
  • reflections, refraction, transparency, specular, normal mapping
  • under water fog
  • fog color changes based on depth and distance
Here's what I've got so far (no reflection or refraction)




Video of planet water on YouTube

Reflection and Refraction

There is no reflection or refraction on the water because I don't know how I will manage that on a curved surface yet. I think what I will try first is only doing water reflection and refraction when you're close enough to the water that it appears to be more flat so I can use conventional techniques.

Underwater Fog

To support underwater I applied a fog to the pixel shader for the terrain based on the terrain depth under water.  I have a outward facing sphere with a shader for transparency, normal mapping and specular.  I also have an inward facing sphere with a shader for when you are underwater looking up at the surface from below.

Unfortunately, the fog shader on the terrain does not line up perfectly with the underwater inward facing sphere so you see cracks at the water edge where there is no fog.  I think I can only fix this issue with post processing.

New Game Dev Machine

I got a new developer machine with an i7 processor and Radeon 5770.  I tried to choose a middle of the road graphics card.  You can see the new game dev machine specs and discussion on eggxpert.com

OGE

Lastly, I've spent a some time working with OGE which stands for "Open Game Engine".    I've created a small RakNet plugin for it and have been trying to get a little client/server action going.  This is a potential game engine that I might adopt for MyFirstPlanet, at least in the development stages to do all the audio, graphics, user interface, networking, gameplay, physics, and scripting that I would have to build myself.  It supports OGRE as a graphics engine plugin so I shouldn't have to rewrite any of my graphics code.

I'll try to post again when I have a video to show of the network tests.  It will mostly just be a couple clients on a server flying ships around in space over a planet.