How Do I Spawn Actors Without Spawning Them on Top of Each Other?

uhyanauhyana Member Posts: 36
edited April 2012 in Working with GS (Mac)
I have one spawner spawning actors at the same x coordinate at a random(50,220) y coordinate that move off to the right off the screen. It's spawning them correctly but sometimes the actors will spawn on top of each other, especially later on throughout the game where it is spawning an actor every 1-3 seconds. How do I make a rule that says it will not spawn an actor close to another actor?

Best Answer

  • JohnPapiomitisJohnPapiomitis Posts: 6,256
    Accepted Answer
    Also make sure to have the spawn behavior above the destroy behavior in that rule. Or else it wont spawn another since itll be destroyed first.

Answers

  • lukey5227lukey5227 Member Posts: 111
    edited April 2012
    I'd think you'd do it like this:

    If self.time < .15 (If the time its been alive is less then .15 seconds)
    and
    colliding with spawned_actor (the enemy or whatever you're spawning)

    Then Destroy Actor
    Spawn Actor (With same parameters as before: x coordinate random(50,220))


    You might also be able to make the time less, to .1 although You need to make sure the entire "If" statement can be processed in the time that you have set. Hope this works!


    EDIT: Found a problem. They'll spawn and quickly go away, still enough for the eye to catch. Here is a way to solve that.

    Start them with alpha at 0 (0% opacity) and set that as the original color. Then make this:

    If (ORIGINAL HERE)

    Then (Do original. Destroy and Spawn another.)
    Otherwise (Change Self.Color.Alpha to 1)

    This should make them not blink.

    EDIT 2: No matter how many more attributes or things I try, they seem to always blink or bounce around. Don't try anything I've suggested :P
  • uhyanauhyana Member Posts: 36
    The first thing you said may actually be a little helpful. I didn't mention that my actors are spawning from the left of the screen to the center. So you will not see them for the first .5 seconds that they spawn. I'll give your idea I try and let you know what happens.
Sign In or Register to comment.