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

0 favourites
  • 2 posts
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • 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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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))

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