shawn's blog

……moar clouds (part tres)…..

Posted in Other by Shawn on January 27, 2011

pretend there’s an accent on the ‘e’

Part two had us finally creating clouds that would spawn. But left alone and these clouds would form a consistent stream of clouds. We can change this by altering the spawn rate for these clouds. Right now, the Instantiate code for clouds is in a separate function, with that function being called in Update.

function Update () {
spawnCloud()  is being called every time we update. However, if we left it alone, with just instantiate, we would many many (many) clouds, something we do not what, even if we wanted a foggy atmosphere. We will need to check if a cloud has spawned and wait. After we wait a certain amount of time, then we could check to see if we wanted another cloud to spawn.
function spawnCloud(){
didCloudSpawn = true;
var instance : GameObject = Instantiate(clouds, transform.position, transform.rotation);
yield WaitForSeconds(27);
didCloudSpawn = false;
Initially, we set didCloudSpawn = false. Then when spawnCloud() is called in Update(), we will check to see if we should spawn a cloud. Since didCloudSpawn = false, we will set it to true and spawn a cloud right away. Now, when Update is called again (it’s called 60 times in one second I think), clouds will not spawn, because didCloudSpawn is set to true. So we must wait 27* seconds. After we wait the alloted time, we will set didCloudSpawn  = false again, allowing for an additional cloud to be spawned.
Last time, I did say we were going add a bit more variety. Well, for now, what we can do is create multiple cloud generator scripts and play with the yield WaitForSeconds line. What I did, was create three different scripts, a slow cloud generator, a normal one and a fast one. They each had different amounts in the WaitForSeconds line, which meant that different generators would spawn clouds at different rates. Which meant, after creating a few fast, normal, and slow generators, we could wind up with….

Moar Clouds!

It would be best to not place two fast cloud generators right next to each other, as this would create a bit too much consistency. So, instead, I was sure to place a slow generator next to a fast or normal one. In addition to this, not all the clouds needed to be on the same plane. They could vary in position on each axis (x, y, and z). This would mean that some clouds would appear to be bigger, when in reality, they’re just closer.

They're actually in 3D space

This isn’t all the variety we could put in. While this isn’t fully implemented, what we can do is give the cloud generator a random interval to pump out clouds. For example, we can say to the slow cloud generator “Generate a cloud anywhere from 30-35 seconds after you generated your most recent cloud” while telling the fast generator to say “Generate a cloud anywhere from 10-15 seconds after your most recent cloud”. This would cause even more organized instability within our skies.

Next time, I may try to put this feature into play, in addition to adding more code to release different types of clouds.

Tagged with: ,

Comments Off on ……moar clouds (part tres)…..