Random spawning isn't working

Hi everyone! in my game I need to have 4 different actors spawn randomly. I watched a video online to help me get started with making it randomly spawn, and I did everything it says. However, when I preview, the same actors spawn over and over again, its not really random, and then it changes scene to my main menu scene. I have no idea why it keeps going back to the main menu scene, or why it wont spawn different actors. Also it doesn't give it time between each spawn, it just shoots out my actors until it changes the scene and then it stops altogether. Any help would be greatly appreciated! Thanks in advance!

Best Answer

  • Beaneh912Beaneh912 Posts: 6
    Accepted Answer

    Okay try this:

    • Give the actor you want to randomly spawn a Boolean Attribute called Selfx (do not tick the attribute box)
    • Then give it a rule: attribute (if [self.Selfx] is false, do; move (whichever direction and speed you want)

    Then create the Spawner actor, I tend to use just a square white block as you wont see the spawner on the screen
    -In Spawner actor give it a timer; every 0.1 seconds (tick run to completion box), change attribute [self.time] to [random(1,x)] where x is any number greater that 1 (random can be found in functions).
    -give the spawner another timer; every 0.1 seconds (tick run to completion box)
    -insert a rule; attribute (if [self.time] = y) where y is a number between 1 and x, do; spawn actor, Click the actor you want to randomly spawn and voila!

    The larger you make the gap between 1 and x the longer the gap between spawns, for example if you set it to [random(1,100)] and set y to 5 the there is a 1 in 100 chance of it spawning, but if x was 10 then there is a 1 in 10 chance and the spawns will be much faster.

    This method is used to spawn the actor randomly from this one position and if you want to spawn the actor in different locations you have to just drag more spawners on in the locations you want them to spawn!

    Hope this helps! :smile:

Answers

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,577

    Hi, your Rules would be nice... we can see what's going wrong then.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • LightningSoraLightningSora Member Posts: 3

    Alright, so for my rules...I made a game attribute called "random" and set it up with a timer that every 5 seconds it would choose a random number from 1 to 4. So its set as Timer every 5 seconds, change attribute game.random to any of my actors that are labeled 1 to 4. After that, I set 4 more rules but all of them are essentially the same. The rule has another timer that every few seconds, if the random number is 1, then it would spawn actor number 1, and if its equal to 2 it would spawn actor 2. And it does spawn the actors, but it spawns the same actors over and over in one round and then it just switches the game scene to my main menu scene. There is no rule to change scene so I don't know how its getting there.

  • LightningSoraLightningSora Member Posts: 3

    @Beaneh912
    Thanks a lot! It worked perfectly. I know I'm late in checking this out, but it worked. Thank you!

Sign In or Register to comment.