Working on a tower defense game and trying to spawn a set unit to spawn randomly anytime of the game. I guess the unit could be random as well but more interested in the timer
Ok so the reason why this may not work is because I had to trick the editor into alowing me to randomize the timer variable. I did so by first making it an integer and then after i had the triggers set-up i set it to a timer. If you know a better way to randomize a timer variable go for it.
If you are a math geek like me and want the spawns to be independent (meaning you can't assume that a spawn is more or less likely depending on when another spawn occured) then you need to use an exponential distribution. There's no function that lets you sample from a distribution, but if you have the right expression then you can do it.
I'll spare you the math involved, but basically you need to generate a random real between 0 and 1, let's call this r.
To sample from the exponential distribution, simply use this expression:
-ln(1-r)/x
x is usually a lambda but I don't know how to type a lambda so I'm typing x. x is the average amount of occurences per a unit of time. It uses the same unit as the expression above, so if you are using this expression to determine the number of seconds between spawns, an x of two will give you an average of 2 spawns per second. If you want, say, one spawn every 10 seconds, you can set x to 1/10.
Be warned that this distribution has no maximum value. Even if you set x to a very high number, it is possible to go hours without a spawn (you did say you wanted it to be RANDOM after all). However, such an occurence would be unbelievably rare.
Working on a tower defense game and trying to spawn a set unit to spawn randomly anytime of the game. I guess the unit could be random as well but more interested in the timer
Ok this may not work and ill explain why after i post this
Ok so the reason why this may not work is because I had to trick the editor into alowing me to randomize the timer variable. I did so by first making it an integer and then after i had the triggers set-up i set it to a timer. If you know a better way to randomize a timer variable go for it.
First on spawn trigger, event would just be sweet ill try to toy with it tonight and see what happens
@coolness5545: Go
If you are a math geek like me and want the spawns to be independent (meaning you can't assume that a spawn is more or less likely depending on when another spawn occured) then you need to use an exponential distribution. There's no function that lets you sample from a distribution, but if you have the right expression then you can do it.
I'll spare you the math involved, but basically you need to generate a random real between 0 and 1, let's call this r. To sample from the exponential distribution, simply use this expression: -ln(1-r)/x
x is usually a lambda but I don't know how to type a lambda so I'm typing x. x is the average amount of occurences per a unit of time. It uses the same unit as the expression above, so if you are using this expression to determine the number of seconds between spawns, an x of two will give you an average of 2 spawns per second. If you want, say, one spawn every 10 seconds, you can set x to 1/10.
Be warned that this distribution has no maximum value. Even if you set x to a very high number, it is possible to go hours without a spawn (you did say you wanted it to be RANDOM after all). However, such an occurence would be unbelievably rare.