0 Favourites

How do I create random enemy spawning?

  • For my survival game, I want to create a system to spawn enemies / AI on the map in random areas. I do not however, want them to spawn in water or on screen to make it seem believable. All water is a seperate sprite / sprites. So I am wondering if it would be possible to make them spawn every couple seconds randomly anywhere on land and away from the player.

  • This may not be the most ideal way to do it, but it should work. Have a small, invisible "spawner" object (just a sprite). Every few seconds, set its position randomly within whatever range you're looking to use (set position X: random(player.X-1000, player.X+1000) and so on). Then, check if it is overlapping a water sprite or water sprite family. If it is, immediately reposition it. Then, right after, if the object isn't overlapping water, call a function or event to spawn an enemy at that location.

  • Thank you very much, I will try this!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • This may not be the most ideal way to do it, but it should work. Have a small, invisible "spawner" object (just a sprite). Every few seconds, set its position randomly within whatever range you're looking to use (set position X: random(player.X-1000, player.X+1000) and so on). Then, check if it is overlapping a water sprite or water sprite family. If it is, immediately reposition it. Then, right after, if the object isn't overlapping water, call a function or event to spawn an enemy at that location.

    Would it be possible to instead have the invisible spawner set position every few seconds to a random place ANYWHERE on the map each time instead of a set distance away from the player all the time? And if so, how? It's kind of essential for my game because I plan to have a somewhat living environment where creatures will interact with eachother around the world.

  • random(0,layoutwidth)

    random(0,layoutheight)

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