How I Avoid Floating Point Precision Issues in Lost Wing

A fairly large change has been made to how the track itself is pieced together at runtime in a (successful) effort to avoid some floating point issues we were experiencing.

When a player managed to survive for extended periods of time without crashing, the issue would become somewhat apparent visually. The further you travelled the more likely the environment and ship would start to flicker and look a bit “wobbly”. This was a result of the floating point math used for storing the positions of objects (and thus their vertices) for rendering purposes not being precise enough .

For those of you of a less-technical persuasion, here’s a little bit of clarification (massively simplified for the sake of brevity – these aren’t “real” number examples!).

Floating point numbers are used in computing to store “non-whole” numbers, i.e. something with numbers after the decimal point. They can store very small numbers (near 0, for example 0.0001) quite well, but their precision becomes much less when dealing with large numbers (so what you intend to be 21496.73321 ends up being 21496.73). In most games this isn’t a problem that causes much annoyance, but for Lost Wing where you travel at a high speed, in the same direction, for a lengthy amount of time, these issues become really exaggerated after a while.

Now how did we fix this? This is where we turn to… Futurama… for inspiration. Their ship, the Planet Express, doesn’t travel anywhere at all, rather, it moves the entire universe around it.

The track in Lost Wing is laid down like a train track, each new section bolting on the end of the last, somewhere in the distance. As your ship moves forward, the track behind you is removed, and new track sections are placed up ahead.

What we do with our updated system is much the same, with one important addition, the entire environment gets shifted backwards the same amount that the ship moves forwards. The side effect of this is that from the player’s perspective, everything looks the same as before (as the camera is also moving with the ship and environment) but, crucially, the immediate environment around the ship is really close to 0 (the “origin” of the world) in terms of object positions etc, so the position of everything you see is super accurate even after seemingly travelling a really long distance.

The result? No more wibbly-wobbly-melty objects!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s