spawning on a random timer
Sparkyidr
Member Posts: 2,033
Having a bit of trouble with this (I know the random thing is not random....but anyways)
I want to spawn some actors offscreen, and then move onto the screen at a set speed. But I want the gap between actors to be slightly different each time.
So I have a rule :
---
Every random (1,2) seconds
Spawn actor x=600 y=(random 20,120)
---
The random y value works a treat...but the timer, just picks either 1 second, or 2 seconds at the start of the scene, and ALWAYS uses that time delay.
I had assumed random 1,2 seconds would give me a random time interval from 1.0 -2.0 seconds. But like I say.. at the start of the scene, it picks either 1, or 2, and sticks to it.
Have I got this totally wrong?????
I want to spawn some actors offscreen, and then move onto the screen at a set speed. But I want the gap between actors to be slightly different each time.
So I have a rule :
---
Every random (1,2) seconds
Spawn actor x=600 y=(random 20,120)
---
The random y value works a treat...but the timer, just picks either 1 second, or 2 seconds at the start of the scene, and ALWAYS uses that time delay.
I had assumed random 1,2 seconds would give me a random time interval from 1.0 -2.0 seconds. But like I say.. at the start of the scene, it picks either 1, or 2, and sticks to it.
Have I got this totally wrong?????
Comments
So random(1,2) will give you either 1 or 2, not 1.3 for example.
Ideally the Timer would behave like you mentioned.
I have a lightning actor on my main menu that crashes every few seconds. I wanted the intervals between crashes to be random as well.
To do that, you have to "reseed" the Timer...
Try this:
Create a boolean attribute in the Actor called 'reseed'. Set it initially to true (check the box).
And set up the Rule set something like this:
Rule
When all conditions are valid:
self.reseed = true
-----Change Attribute: self.reseed To: false
-----Timer: After random(1,2) seconds
----------[spawn Actor]
-----Timer After 0.5 seconds , run to completion
----------Change Attribute: self.reseed To: false
thanks