How do I spawn enemies at random (accessible) points?

  • For a platformer, what would be a good way to go about this? Of course, I don't want them to pop in within the player's vision or in places they can't even get to.

  • Also, preferrably still in close proximity to the player.

  • No one?

  • Let's say your object that your spawning is named, "Enemy". And your trying to spawn him every 5 seconds. I know that's not what your doing, but you didn't provide enough details.

    So try putting this Event,

    Every 5 seconds > System create object, Enemy.

    Put what layer you want the Enemy on.

    For the coordinates of spawning use, X:random(width of your layout)

    Y:random(height of your layout)

    So Every 5 Seconds a "Enemy" spawns at a random spot anywhere on the layout.

    -But your question is what if he spawns in a block or somewhere he can't move?

    To solve that, use this.

    Enemy is overlapping Platform>Destroy Enemy

    >Create Object "Enemy" on layer 0 (random(width of your layout)) (random(height of your layout))

    Basically when he's created and he is somewhere he is not supposed to be, he will be destroyed and placed in a new spot, if this keeps happening he will keep spawning until there is somewhere "spawn able."

    This is a bad example but it can be worked with, if it is not fitting your game tweak it the way you want it or just not use it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Let's say your object that your spawning is named, "Enemy". And your trying to spawn him every 5 seconds. I know that's not what your doing, but you didn't provide enough details.

    So try putting this Event,

    Every 5 seconds > System create object, Enemy.

    Put what layer you want the Enemy on.

    For the coordinates of spawning use, X:random(width of your layout)

    Y:random(height of your layout)

    So Every 5 Seconds a "Enemy" spawns at a random spot anywhere on the layout.

    -But your question is what if he spawns in a block or somewhere he can't move?

    To solve that, use this.

    Enemy is overlapping Platform>Destroy Enemy

    >Create Object "Enemy" on layer 0 (random(width of your layout)) (random(height of your layout))

    Basically when he's created and he is somewhere he is not supposed to be, he will be destroyed and placed in a new spot, if this keeps happening he will keep spawning until there is somewhere "spawn able."

    This is a bad example but it can be worked with, if it is not fitting your game tweak it the way you want it or just not use it.

    I did kind of figure something out like this, but I want it so that enemies spawn relatively close to the player but not within their view.

  • You could make invisible spawn points and have a condition that prevents them from spawning enemies if they are on screen. A really cheapo way of making them spawn if they're in a specific distance would be to maybe attach a big invisible shadow to the player so you could have "If spawner is overlapping shadow and not on-screen" added to its conditions.

  • You could make invisible spawn points and have a condition that prevents them from spawning enemies if they are on screen. A really cheapo way of making them spawn if they're in a specific distance would be to maybe attach a big invisible shadow to the player so you could have "If spawner is overlapping shadow and not on-screen" added to its conditions.

    That is a better way, XD!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)