How do I make a certain enemy spawn in random areas.

Just started using Construct 2? Post your questions here

Post » Tue Jun 02, 2015 12:43 am

So, I have a certain enemy that spawns twice every 6 seconds, but I don't know how to set the random spawning. For my previous swarming enemy, I made 4 spawn every 4 seconds, one on each of the 4 sides of the layout. I did random spawning for each of the 4 (random as in where on that side of the layout they spawn).

Now, because I only have 2 enemies spawning every X amount of seconds, I want one of them to spawn on random areas on either the top & right side of the layout / the other to spawn on random areas on either the bottom & left side of the layout. They spawn outside of the layout (about 50 - 100 pixels from the edge) and the game is top-down survival shooter.

So basically the outcome will be having 2 of these types of enemy spawning every X seconds, one of them on either the top or right side of the layout (and in a random area on it. For example : more to the left or to the right? More towards the bottom or the top?) and the same for the second except the second on either the bottom or left of the layout.

Sorry for repeating myself a million times, it's hard to explain. Hoping someone can help me. Thanks! :D :oops:
B
28
S
11
G
4
Posts: 77
Reputation: 4,321

Post » Tue Jun 02, 2015 9:20 am

I would do something like this:

Give the enemy an instance variable WhereToSpawn

every x seconds
> system create enemy at (0,0)
> enemy set variable WhereToSpawn to choose(1,2)
> system create enemy at (0,0)
> enemy set variable WhereToSpawn to choose(3,4)

enemy on created
-- Enemy compare variable WhereToSpawn = 1
> enemy set position: x = random(viewportleft(0),Viewportright(0) y = Viewporttop(0)-100
-- Enemy compare variable WhereToSpawn = 2
> enemy set position: x = Viewportright(0)+100 y = random(Viewporttop(0),Viewportbottom(0))
-- Enemy compare variable WhereToSpawn = 1
> enemy set position: x = random(viewportleft(0),Viewportright(0) y = viewportbottom(0)+100
-- Enemy compare variable WhereToSpawn = 1
> enemy set position: x = Viewportleft(0)-100 y = random(Viewporttop(0),Viewportbottom(0))
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest