How do I make enemies spawn from every places

0 favourites
  • 5 posts
From the Asset Store
Spooky Places game assets for 2D endless runner action adventure game.
  • So I used a template to make my game, and I can't understand how variables work.

    Problem is my monsters are only spawning from the right, I want them to spawn randomly from both sides, and up and down. In short, from all directions. And all from outside the window.

    How to do that?

    These are the numbers:

  • not the best version, but the easiest to understand

    The global variable is TEXT and it just stores from which direction the enemy should appear

    Edit: North, South, West, East

    check the variable and place it slightly out of the layoutSize (30px)

    to check if it is working just replace 30 with 0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Are you some kind of Wizard? That worked p-e-r-f-e-c-t-l-y. Like a charm. Thank you so much.

    Just one question out of curiosity, is "N", "S", "E," "W" by default recognized as directions by Construct 2? So whenever I use these texts as variables, it will read as directions?

    not the best version, but the easiest to understand

    The global variable is TEXT and it just stores from which direction the enemy should appear

    Edit: North, South, West, East

    check the variable and place it slightly out of the layoutSize (30px)

    to check if it is working just replace 30 with 0

  • THX,

    [quote:1vbxervc]Just one question out of curiosity, is "N", "S", "E," "W" by default recognized as directions by Construct 2? So whenever I use these texts as variables, it will read as directions?

    NO

    it's just what I have chosen. You can take numbers or "L" "R" "U" "D" or whatever you like e.g. "left"

    Line1: set variable to random direction in this case N, S, E, W

    Line 2-5: check what variable is set

    e.g. if "N" then create object on top of the screen

  • In your original code, you spawn monsters in the layout at a X position of 1500 pixels and a Y position of between 0 and 1024.

    The X position was always 1500, which makes it "right" if your windows size is less than 1500 pixels wide.

    In your case, you could use further expressions :

    In the X field : choose(random((Monster.Width*2)*-1,(Monster.Width) *-1)), random(LayoutWidth+Monster.Width, LayoutWidth + Monster.Width*2))

    This made it choose between two location.

    One location is a random value between - Monster.Width (the width of your Monster instance * -1) and double its width.

    So this is the left border of the screen, negative values.

    The other location is past the Layout width (right of the screen/layout) + an interval between monster's width and monster's width *2

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