Spawn Rule: How to spawn everywhere except a certain area???

Games4lifeGames4life Member, PRO Posts: 279

I am currently creating another game that I am wondering how to spawn enemies everywhere on the map except a certain "safe zone". Anyone know how to do this?
Thanks
~G4L

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    I think I'd try spawning everywhere on your map and then add an invisible actor to act as the safe zone. Then create a rule in the enemy that if it touches the safe zone actor it is destroyed. So if that enemy were to spawn in the safe zone it would be immediately destroyed.

  • Games4lifeGames4life Member, PRO Posts: 279

    @jamie_c said:
    I think I'd try spawning everywhere on your map and then add an invisible actor to act as the safe zone. Then create a rule in the enemy that if it touches the safe zone actor it is destroyed. So if that enemy were to spawn in the safe zone it would be immediately destroyed.

    Thanks i'll try that!

  • owen_dennisowen_dennis Just a guy, you know. Member, PRO Posts: 236

    Something to keep in mind with what @jamie_c said, it's possible that using that method you can see a flick for one frame of the actor existing before its destroyed. A way to fix that is to make sure your destroy function is in the top rule within the actor. Another way is to make your actor invisible by turning off visibility or making the alpha 0, then having the actor become visible if it hasn't been destroyed by the big square. I do this with randomly spawned coins.

  • Games4lifeGames4life Member, PRO Posts: 279

    @owen_dennis said:
    Something to keep in mind with what @jamie_c said, it's possible that using that method you can see a flick for one frame of the actor existing before its destroyed. A way to fix that is to make sure your destroy function is in the top rule within the actor. Another way is to make your actor invisible by turning off visibility or making the alpha 0, then having the actor become visible if it hasn't been destroyed by the big square. I do this with randomly spawned coins.

    Can you give me a sample piece of code to give ideas on how to start?
    Thanks!!

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited April 2016

    @Games4life said:

    @owen_dennis said:
    Something to keep in mind with what @jamie_c said, it's possible that using that method you can see a flick for one frame of the actor existing before its destroyed. A way to fix that is to make sure your destroy function is in the top rule within the actor. Another way is to make your actor invisible by turning off visibility or making the alpha 0, then having the actor become visible if it hasn't been destroyed by the big square. I do this with randomly spawned coins.

    Can you give me a sample piece of code to give ideas on how to start?
    Thanks!!

    Something like this:

    Change Attribute: self.Alpha = 0 (add this as your first bit of code on the actor)
    Rule: if collides with invisible actor (whatever you call this invisible actor):
    ... Destroy
    Otherwise
    ... Change Attribute: self.Alpha = 1

    And then all of your existing code below

    Keep in mind that if the actor ever moves onto this invisible actor at a later time it will be destroyed. If your actors move and you don't want that to happen then something like this should work:

    Change Attribute: self.Alpha = 0 (add this as your first bit of code on the actor)
    Change Attribute: self.justSpawned = true

    Timer: After 1 second
    ... Change Attribute: self.justSpawned = false

    Rule: if collides with invisible actor and self.justSpawned = true:
    ... Destroy
    Otherwise
    ... Change Attribute: self.Alpha = 1

Sign In or Register to comment.