How do I create random enemy spawning?

Get help using Construct 2

Post » Mon Apr 11, 2016 12:29 am

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.
B
28
S
11
G
4
Posts: 77
Reputation: 4,321

Post » Mon Apr 11, 2016 3:33 am

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.
B
103
S
38
G
19
Posts: 962
Reputation: 17,986

Post » Mon Apr 11, 2016 3:35 am

Thank you very much, I will try this!
B
28
S
11
G
4
Posts: 77
Reputation: 4,321

Post » Tue Apr 12, 2016 1:56 am

C-7 wrote: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.
B
28
S
11
G
4
Posts: 77
Reputation: 4,321

Post » Tue Apr 12, 2016 1:59 am

random(0,layoutwidth)
random(0,layoutheight)
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303


Return to How do I....?

Who is online

Users browsing this forum: ivanski1983 and 14 guests