- Home /
Randomized weather, little stuck
Hi,
Edit: The main problem we're having is finding an equation that fades an alpha blended material based on the game speed. If anyone can point us in the right direction or give us an example that'd be great. Once we figure this out then we can work on randomizing it.
So far we have everything figured out with our system, but we're just a little stuck on the last part which is randomized weather. We have been at this for days and can not get it working.
We have a minute, hour, day, and month tracker. We have thunder, lightning, rain, everything, but we just need a way to enable them based on randomization.
How could we go about this? I think the easiest way would be to use a random.range then have an if statement get a random number, if that random number is reached, do the what's in the if statement for a randomized period of time based off the global dayLength.
I'm a pretty decent programmer, I'm just not sure how to do the above. We also need to have the rain and clouds fade in and out when a storm approaches. So maybe have multiple if statement gradually fading the storm in then out?
Is there a better way of fading a material than this, it doesn't seem to work correctly:
heavyClouds.renderer.sharedMaterial.SetColor ("_TintColor", Color.gray / dayLength);
If there is, how can I fade the fade time based on the dayLength, as our system has a global time that is all synchronized, like game minute, hours, days, cloud speed, ect.
This is a quick function which should take care of the could fading, but it doesn't work right.
function weatherCalculator () {
Hour = Random.Range(0, 24);
heavyClouds.renderer.sharedMaterial.SetColor ("_TintColor", Color.white /
dayLength);
if (Hour == 14)
{
Hour = Random.Range(0, 24);
heavyClouds.renderer.sharedMaterial.SetColor ("_TintColor", Color.gray /
dayLength);
yield WaitForSeconds (random*dayLength);
}
If anyone could help me out it'd be much appreciated. I'll be sure to mark as answered if the answer gets this working.
Thanks
Is dayLength a constant denoting the lenght of a day, or is it a variable that shows the current time of day?
Also, it doesn't seem like the Hour variable is actually used anywhere.
This is only a small snippet of our code, it's 200+ lines, but I'm not going to post the whole script for obvious reason, I'll try to explain the best I can. Yes, the length of a day is a constant of dayLength. The $$anonymous$$ute, hour, day, ect all have their own variable for display and they're all calculated correctly.
I want the hour to be the random.range because I want it to be based off of the actual in game hours.
If you have another way to do this I'm sure I can convert it and make it work. I just need an if statement equation and a way to fade the clouds when a storm comes and goes based on the dayLength.
Answer by WillTAtl · Mar 06, 2012 at 01:13 AM
might be more elaborate than you're looking for, but one-dimensional perlin noise would do quite nicely. Searching perlin noise will give any number of examples. At the simplest, a single 1d perlin function could control both the clouds and rain; if you wanna get fancy, you could create multiple functions; one for cloudiness, one for rain, one for fog, etc, and multiply where appropriate - for example, it can't rain without clouds, so the rain value is multiplied by the cloudiness value, then if clouds is 0, it can't possibly rain, and the more clouds, the more rain.
Sounds interesting, can you explain a little more? Also how does the perlin noise work with textures, I'm not familiar with it.
well, I wasn't thinking of using it for the textures - it sounded like you had textures already, and were just looking for a way to vary the weather over time in a smooth and realistic way. You could use perlin noise to make the clouds themselves, with some cleverness even to position rain drops if you really wanted, but explaining perlin noise in that detail is rather much for a question on UnityAnswers.
just to give you an idea how it would work, a perlin function gives pseudo-randomness. In your case, it could take time as the parameter and give back a % cloudiness. The way perlin functions work, the value will fluctuate smoothly over time; just pass in any time value and it'll give a cloudiness % which will consistently blend from the previous and to the next.
I understand, but it seems complicated as I can't find much documentation on it. We already have cloud textures I was just wondering if the could be generated, but our textures will do.
As for the % of cloudiness, can you give me an example? I'm not familiar with perlin noise. Or is there another way of fading the material to make it disappear then reappear. We pretty much just need the material to fade in then fade out and disappear.
How could I an if statement for this?
I understand, I've searched articles on perlin myself in the past and many of them are a bit thick. It's actually far, far simpler than most of them make it seem. The gist is you specify some interval - lets say one hour (if it was textures, it'd be distance rather than time). You generate random values for each time - ideally you write a function that will take in a given time t and always return the same random value for that time, but if you're pregenerating it or doing it in a single-player scenario where you don't need consistency between sessions, you could just use Random.rand. That gives you a random value - in this case, the amount of rain or clouds - for each hour, ex., it might be 0% at noon, 25% at 1pm, 12% at 2pm, 50% at 3pm, 100% at 4pm.. these will be completely random, unrelated to each other. Then you just use an interpolation function to get the rain level between those for any time inbetween. Liner interpolation might work, but could be "jagged" (in this context, meaning clouds instantly switch from growing sharply to fading sharply). A good overview of interpolation functions is available here http://sol.gfxile.net/interpolation/
as I said originally, this may be more involved than you had in $$anonymous$$d :) but it's really not as complex as it seems, particularly in a simple 1d case like this!
Your answer
Follow this Question
Related Questions
Fading in between two materials overtime? 3 Answers
fading between skyboxes 1 Answer
Changing / Adding Material over Real-World Time 0 Answers
Repeat Function 1 Answer
Fade in a GameObject Material? 1 Answer