Kings Can Fly

by Firedroid

Moving ships

Posted by Roy On June - 1 - 2011

The basis for our game is a grid of tiles. In our setup we’ve got a grid and tiles, with every tile aware of its neighbours (left, right, above, below). This makes lookups for determining the next tile to navigate to faster and easier.

The airships need to navigate this grid and turn away from mountains (because that’s what the airstream does). While navigating the grid we want the ships to move exactly one tile per ‘tick’ (a tick is a arbitrary amount of time, the rate at which ticks go by basically control the speed of the game). This isn’t very hard, all we need to do is make the ship pick a new tile when a tick has passed. Movement still needed to be smooth however and since we will be making turns and moving up and down, simple interpolation wasn’t going to work.

So we’ve chosen to use Bezier Curves to move our ships. The basis for this system is that the ships should move on the current tile towards their next tile, with the beginpoint being between the last tile and the current tile, and the endpoint being between the next tile and the current tile:

The begin and end points (p0 & p2) are shown in yellow, with the control points (p1 & p3) being shown in green, with lines from the begin/endpoints to them in green as well. The blue line is the bezier curve itself, and the red point is the ship’s position. The ships current direction is shown as a red line.

I’m quite happy with the way this turned out, the ships seem to move naturally. Of course there’s a lot to do to make the ships movements appear more natural, such as swinging from side to side, bobbing up and down a bit, etc. Still, this is a very nice basis for movement and I hope it’ll continue to work well.

Add your comment