DevLog #5 - Environment

In Cloudship, the environment has to be an actor. It cannot be passive or visual only, it must affect the choices that the player takes. There are two main parts to it: ground and wind. The ground will be an infinite desert (as per the game) that will hold resources to collect, either in the form of coal deposits or wrecks/flotsam of old Cloudships.

Wind Take 2

In my previous dev blog I was using huge spinning discs to model wind. I thought of it as intersecting record players that the Cloudship would sit on. Although it worked OK, it became difficult to make it act like real weather. Rather than get caught in the flow, you'd get flung off the side of the disc. Physically correct but not really what I was after.

I was pointed at Perlin Noise flows beautifully described here:

Look at how little code the dude writes! That p.js library is the business.

I already knew about Perlin noise as I was using it to generate the discs. I moved over to generating a grid of arrows and then turning them using Perlin noise. I ended up with this:

As you can see, the arrows flow nicely around. I tested this extensively and found that the flow inexorably moved in a single direction. If you imagine Perlin noise as a cloudy image:

Then each pixel is your co-ordinate in space and the darkness of the pixel is angle the wind is pushing at. Black would be the wind at 0 degrees and white would have the wind blowing at 360 degrees and then all the greys are between that.

A side effect of Perlin's lovely cloud smoothing is that very few points are fully black or fully white. The vast majority of them are grey, which means angles between 90 and 270, with the majority being 180. So you would be pushed inexorably in one direction.

That looks OK at first with the game as it is but I plan to put in towers and wrecks in really tricky spots. The only kind of tricky spot you could make here is going to fast. Instead, I still wanted that wind model where you get blown around a pressure centre.

So I decided that the black areas would be "pressure zones" and the white areas would be "everywhere else". Like real isobars, the wind flows at 90 degrees to the pressure gradient. In this case the gradient is just the gradient of black to white. When a cloud or cloudship or anything blown by wind needs the force applied by the wind (each physics update) then it calls a method that finds the gradient by sampling around the caller's location and turning it by 90 degrees. There's really not much code to it, although it took me a while to shave it down to something readable.

For the magnitude, I'm just getting the Perlin Noise value, which isn't ideal. Really it should be the magnitude of the gradient. The faster that black changes to white, the faster the wind. Another alternative is to use a separate Perlin function to give me the wind speeds and then multiply them together. Worth thinking about.

The picture below shows the pressure system. The arrows get smaller around the black pressure centre (I reversed this later so that black is stronger) the colour shows the direction.


Clouds are going to be an ongoing battle. At time of writing, I like the concept but I don't like the way they render. I began by putting some particle emmitters into the scene and have them call the same wind function as the Cloudship. They follow the wind with more strength, having no thrust of their own. Here are a bunch of clouds with the default particle effect.

I want the look to be stylized low-polygon and for the clouds to look like the fat, white lumbering things. I added a procedural sand infinite terrain using a similar process to the arrows, took away the blue floor. It's starting to look like an actual game.

I added fog and a new sky box, increased the amount that was rendered and it all went a bit sparse! I might have to spawn clouds in clumps (using Perlin noise again!) but to begin with I want to make them white, more solid and randomise their size.

I'm also going lift up the floor.

So that's all in this update. You can download the latest release "Sand and Fog" on GitHub.

All comments, questions and thoughts welcome!