How to spawn a random actor?

wroachbarrettewroachbarrette Member Posts: 101
edited June 2012 in Tech Support
I was wondering if anyone knew a way to make a method that will randomly spawn an actor from a given list or tag, any help would be appreciated

Best Answer

  • jckmcgrawjckmcgraw Posts: 647
    Accepted Answer

    -Create an index, game attribute called random (or something like that) and set it to 0
    -Create boolean attribute called spawn (or whatever)
    -Create an actor called control and put it on the scene
    -In the control actor, make a rule that says if game.random = 1 & game.spawn is true, spawn actor in pos x, y
    -Rule: if game.random = 2 & game.spawn is true, spawn a different actor (wherever you want it)
    -Rule: if game.random = 3 & game.spawn is true, spawn a different actor (wherever you want it)
    -Do this for however many actors you might want spawned
    -Put a timer in: Every x amount of seconds, change game.random to {function}random(1,(however many different actors you have)) & change attribute game.spawn to true.
    -Rule: if game.spawn is true, timer: after 0.1 sec, change game.spawn to false.

    This should do the trick! Let me know if it doesn't work. If you want the actors randomly spawned on touch, just implement that instead of an "every x amt of seconds" timer. Also, since you are using a few timers, I would recommend checking out this thread for that if you haven't already...

    Hope this helps!
    Jack McGraw
Sign In or Register to comment.