Random monster spawn, but not on player screen

0 favourites
  • 10 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hello!

    (Sorry if I write badly, but English is not my native language.)

    I keep on making a top-down shooter, and have stopped at one small problem I'm sure you guys can help me with. I am completely new to the Constructor 2 and use the free version.

    What I'm trying to achieve is:

    To spawn monsters total random all over the playfield, but not within the players sight (screen area).

    I use this now, and this monster spawns all over the playfield, also within the player screen area.

    Condition: System -> Every X seconds ->

    Action: System -> Create object -> Monster, layer 1, Random (X), Random (Y).

    Is it right that I intend to use the common condition "Is on screen" to fix this?

    If anyone has the time to write down an example, or if you could point me in the right direction. I would really appreciate this!

  • I'm not a math expert, so I think my expression is not so good, but you can try this. Find a X coordinate, then Y according to X:

    Add a global variable ("randX").

    Condition: System -> Every X seconds ->

       Action: Set randX to random(0,LayoutWidth)

       Action: System -> Create object -> Monster, layer 1, randX, randX<ViewportLeft(0) | randX>ViewportRight(0) ? random(0,LayoutHeight) : choose( random(0,round(ViewportTop(0))), random(round(ViewportBottom(0)),LayoutHeight) ).

    You may have to adjust viewport layer numbers, and rounds.

    Look at the manual for more details (expressions, system expressions)

  • Thanks for your advise. I will try this out in some days!

  • If you've got your player behavior to stay inside the layout along with the scrollto behavior so that you never see outside of the layout, you can spawn the monsters outside of the layout (assuming you don't have your monster with the destroy outside of layout behavior).

    If you use rand(-500,layoutwidth+500),rand (-500,layoutheight+500), then check to see if the monster's X is less than 0 OR greater than your layoutwidth and the Y is less than 0 OR greater than your layoutheight. If they aren't, then move them outside of the layout and let 'em go.

    If you wanted to get even fancier you could do something like this:


    capx (R117)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • if that doesn't work try adding a condition to the monster

    monster - on created > set position Random (X), Random (Y)

    is on screen

    the idea is to check if it's on screen when it is created and if so set it's position elsewhere.

  • wretchedshark Only problem with that setup is if the random(x), random(y) put the monster inside the screen again. That event only will fire once when the monster is created.

    Now, if you were to put a while & monster is on screen as a sub even there and set the position to random again that would work.

  • edit: mistake

  • Well this is handy i was just about to implant this into my game but now i don't have to figure it out myself. Thanks!

  • theubie wretchedshark

    Thank you guys! This helps me a lot.

  • Just had a thought that might work and would take much less events.

    I have some planets that orbit a star. I wanted them to have a random starting position at the start of every game so i made a global variable which is set at the start of the layout to random(360). The planets take their stating position from the global variable. If you would create a radius outside the layout size they would spawn at a random location outside of the layout size. Of course an enemy that spawns at 45 degrees would enter the layout sooner then an enemy that spawns at 90 degrees but as long that doesn't matter it should work.

    global variables

    radius = number bigger then the layout

    randomspawn = random(360) you can set this at on every tick

    spawn X and Y



    Edit: Sun is obviously the center of the layout <img src="smileys/smiley2.gif" border="0" align="middle" />



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