How to spawn a random actor?
Hi guys,
So i am trying to have two different actors spans randomly. I know how to make an actor spawn others on a timer but how do i make it able to spawn 2 different actors and and randomly not alternating.
thx
Best Answers
-
Socks London, UK.Posts: 12,822
@Game Chef said:
I than created a rule that says
when attribute (spawn random) = 1, spawn blue actor.
otherwise: when attribute (spawn random) = 2 spawn red actor.Just a quick note, you don't need a rule in the otherwise section, you are choosing (randomly) between 1 and 2 . . . the first rule says if the number is 1 then spawn a blue actor, therefore the otherwise section of this rule can only be triggered if the number is not 1, and seeing as we are only choosing between 1 and 2, the number must be 2, so there is no need to check if the number is 2, as only 2 can trigger the otherwise section.
Keeping your code 'clean' (avoiding unneeded or needlessly complex rules) keeps GameSalad running efficiently.
Answers
Change A to random (0,1)
When A = 1
--Spawn Actor 1
Otherwise
--Spawn Actor 2
Hi socks,
thx for the reply and i now have a random attribute so the actor is spawning them both but for some reason it is going actor 1 actor 2 actor 1 actor 2... instead of random. Any ideas?
I have a calculation on the screen in front of me, it's giving me the wrong result, any ideas why it's doing this ?
Sorry i can't post pictures
Type it out then?
So i created an integer of (spawn random) and set it to change attribute every 1 second to random(1,2).
I than created a rule that says when attribute (spawn random) = 1, spawn blue actor. otherwise: when attribute (spawn random) = 2 spawn red actor.
So i got them spawning randomly but i have a new problem as i want them to increasingly spawn faster and faster once you hit a certain amount of points. I tried creating an integer of (spawn rate) and set it to 1 in the attributes section near the actors. I than created a rule that says when (game score) = 10, change attribute (spawn rate) to (spawn rate - 0.5).
I than realized you could only have full numbers for integers so i tried it with real, but nothing happens and the spawn rate stays the same unless you go and change the number of the attribute.
Any help would be much appreciated,
thx
This might work
if game.score >=10 **
timer every 0.5 seconds
random(1,2)
**otherwise
timer every 1 second
random(1,2)
so that works but once it changes to 0.5 it is still spawning every 1 second as well unless i delete the rule to spawn every 1 second but than nothing is spawning and you can't get 10 points and the rule will never change for it to be spawning every 0.5 seconds.
I hadn't put the spawn every 1 second in otherwise but it all works fine now.
Thank you so much for helping me Icebox.