Dev Blog: Landships part 2: Sproing!

Airships: Conquer the Skies
18 Mar 2015, 11:51 a.m.

Having covered the kind of stompy war machines I want to make in the last blog post, let's get into how to implement them.

Mostly, landships and airships can be treated the same. Buildings are technically a kind of immobile airship, so landships aren't much of a stretch. The difference is that a landship is held up and propelled by tracks or legs, rather than through Suspendium and propellers.

The question is how the ship navigates changing terrain. What happens when there's an upwards step? A real vehicle tilts when it drives up or down a slope, but the game engine can't support rotation of ships without massive complication.

On a slope, I want to keep the body of the ship level, but raise it up gradually so it can adjust to the new terrain height. To do this, I add a suspension, a set of springs that raises the landship off the ground. The ship won't bump against minor changes in terrain, and its vertical position gets smoothly adjusted. The springs aren't real physical objects, so they won't bump against the side of a hill. The tracks or legs the ship uses will get drawn on top.

This is what happens when the ship encounters a step upwards: As the springs move across the ground, the first one encounters the new height. It becomes more compressed and the additional force starts shifting the body of the landship upwards. As more springs move over the new area, the ship keeps on rising. Of course, if the hill is too steep, or the ship too heavy for the springs to push it up much, it will get stuck. But that's fine, that's realistic.

It also works when going down, though again the ship can get stuck if it doesn't have enough clearance.

So let's start implementing these springs, which will be attached to new tracks/legs modules. I start by creating a Spring class and putting in code so it can find the closest bit of ground. That gives me the length of the spring, and from that the upwards force the spring exerts, which can be easily plugged into the physics engine. Create a test module and put it on a building - and it sproings up!

Great! The next step is to actually introduce landships as a type of construction, beyond ships and buildings. Turns out that lots of things key off "is it a ship or a building", which is too specific. What matters is "can it move" and "does it fly", which nicely separates airships, landships and buildings in how they need to be treated.

Next time: Creating some basic landship modules that are able to both hold up and propel the ships.