Spawning with a timer problem
Hey all!
So I'm using a Timer-Every.Random(.8, 2.5) Seconds/Spawn actor, then it chooses a location from a table. The issue is that it spawns like crazy instead of doing what it is told to do... Is there a better, more accurate to small numbers, way of spawning actors with randomized timing?
Thanks!
So I'm using a Timer-Every.Random(.8, 2.5) Seconds/Spawn actor, then it chooses a location from a table. The issue is that it spawns like crazy instead of doing what it is told to do... Is there a better, more accurate to small numbers, way of spawning actors with randomized timing?
Thanks!
Best Answers
-
tatiang Posts: 11,949
If you use a random expression inside of a timer, it chooses a random value ONCE and uses that for the timer (e.g. every 0.8 seconds). It does NOT reset the random value for each iteration of the timer.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
-
tatiang Posts: 11,949
I think you could do something like this:
change attribute self.startTime to self.Time
change attribute self.endTime to random(0.8,2.5)
When self.Time >= self.startTime+self.endTime --> Spawn actor; change attribute self.startTime to self.Time; change attribute self.endTime to random(0.8,2.5)
(edited)New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
-
tatiang Posts: 11,949
I updated the rules a couple times and I'm working on a quick demo right now.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
-
tatiang Posts: 11,949
I got it to work but only with larger random values. As soon as I drop it down to (0.8,2.5), it doesn't work consistently. But here's the demo if it's of use to you.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
-
tatiang Posts: 11,949
Okay, I thought this might be the problem. The random function only returns integer values. So random(0.8,2.5) returns values from 0 to 2. If you want real values, you'll need to pick a random integer and then divide it or add/subtract to get a decimal value. Otherwise, it works pretty well with random(1,3).
Also, there's no need for self.startTime. It's a little cleaner to just do change attribute self.endTime (I actually called it self.spawnTime this time around) to self.Time+random(1,3) and then check when self.Time>=self.endTime.New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Answers
Any thought about this?