• Register

Autumn is a game in which you experience a relaxing atmosphere for growing and learning on a spiritual level. in each game you play as a Spirit which depends on the natural world for its own growth. As you help the world around you to thrive, you get back spiritual energy in return. In Autumn, while the trees are shedding their leaves, orbs of Prana are released into the air, which you can absorb. Your own Prana can be utilized to help and change the world around you and to obtain spiritual teachings. More than levels or in-game progressions, Autumn's focus is on the growth of the most important being: yourself. There are no time-limits, no enemies to defeat, no goals to reach… except the ones you set for yourself. Relax, learn, grow… and enjoy Autumn.

Report RSS Simulating dynamic weather effects (rain)

So a couple of days ago I posted a screen recording of a feature I worked in the weekend for Autumn: dynamic rain effects. Somehow, plenty of people got interested in it and asked me how I did it and if I could share the code. I don’t share the code, not because it’s top-secret or I am afraid of someone stealing my game but because it is very tightly integrated in other parts of the game, and so might be a bit messy to understand. Instead, I decided to write this.

Posted by on

But first, the video: (somethings have already changed since this recording was made, but anyway…)

So the whole thing is quite simple, actually. But let’s go step by step.

The first thing is to decide when the rain starts and ends, its duration and intensity. So I have a function that makes these decisions, that is called on the start of the game, and every time the rain finishes. In Autumn, the game time follows a year cycle, mapped from 0 to 100. So the beginning of winter is 0, and the end of autumn is 100, then the whole thing repeats in cycles.

So I can assign the rain to start and end at specific times. To do that, I have a few important variables:

  • rain_start_time
  • rain_end_time
  • rain_climax_time
  • rain_climax_strength
  • rainctl

The first two should be self-evident. The climax time defines when the rain intensity should reach the climax_strength (ranges from 0.3 to 1). Having this four variables allows me to create more realistic rain effects, as they will be different every time.

The last one, rainctl, is the main variable, that holds how much rain there is at any given moment (ranges from 0 to 1). Its value is normalized according to the current game time position relatively to the rain start, end and climax times and the climax strength

So, for example, I can have rain that has the climax_time very close to the start_time, which will make it start very fast and then slowly wane away. The graphic below shows two different scenarios, that illustrate this

rain-graph

Now we have to put all this into something the player can see (and hear!). The value of rainctl directly affects three different aspects of the rain:

  • amount of droplets on the screen glass
  • amount of rain (lines)
  • volume of the rain sound

Having just one variable (rainctl), makes things really easy!

The droplets on the screen are very simple “objects” that have a few properties which make them feel a bit more real:

  • size (random)
  • falling speed (random, depends on size)
  • initial color alpha

On every update call, I reduce the alpha of each drop, until it becomes 0 and gets removed. The rainctl value indicates the maximum number of drops that can be on the screen. The falling speed depends on the size so that bigger drops seem to fall faster and smaller ones.

The rain lines are just randomly drawn grey semi-transparent lines. I also use the rainctl value to set up a maximum number of lines that get drawn.

And finally, the volume of the rain sound is directly set by rainctl, as it also ranges from 0 to 1.

So there it is, quite simple! It took me a whole day to do it, because I had to come up with the idea, try different ways of doing it and finally settling down with this one and tuning it up.

Besides this I also do a bunch of sanity checks that are more closely related with Autumn (like, few chance of rains in summer, or only light showers, etc).

See you soon!

Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: