How to spawn instances in specific points at XY cordinates without overlapping objects?

From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • The title is pretty long, ik. Hello! I'm making some undertale surviving game and it's going pretty well at least. I have already done this in other games but in some way that isn't too good with a lot of events, so i need a help.

    The image below has the exactly shape of an spawn area that i want to spawn Spears. The spears should spawn randomly through it's X and Y, but without spawning inside the player's box, for obviously reasons.

    imgur.com/a/ByDQUcp

    I want to do this trick in few events or at least only 4-5 by just using math to check if it's inside the box or if it's outside by an example of area: X=200 to X=500 and Y=300 to Y=700.

  • One way is to just spawn the objects in random positions and if the object collides with the player move it to a random position.

    Here’s one possible example. Create it on the player, and repeatedly move it to a random position till it’s not touching the player.

    On function “add spear”

    — Create spear at (playerbox.x, playerbox.y)

    — while

    — spear: overlaps playerbox

    — — spear: set position to (random(windowWidth), random(windowheight))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • One way is to just spawn the objects in random positions and if the object collides with the player move it to a random position.

    Here’s one possible example. Create it on the player, and repeatedly move it to a random position till it’s not touching the player.

    On function “add spear”

    — Create spear at (playerbox.x, playerbox.y)

    — while

    — spear: overlaps playerbox

    — — spear: set position to (random(windowWidth), random(windowheight))

    Thanks for the answer! It's actually working, but i'm using an object with ScrollTo, so when using (random(windowWidth), random(windowheight)) isn't spawning in the place that i want. Instead it's possible to spawn through an specific area without it being an object or the window?

    Or, if i need to use some sprite with a larger area that the spears will spawn on it (like making the spears spawning spreaded inside an invisible sprite box), how can i do that?

  • Just replace the random() stuff to whatever you like. Random can be defined as random(min, max) of that helps. All a box is a low and high value vertically and horizontally.

  • Just replace the random() stuff to whatever you like. Random can be defined as random(min, max) of that helps. All a box is a low and high value vertically and horizontally.

    But, how i can get an min and max value of a sprite size/position?

  • The expressions

    Sprite.bboxLeft

    Sprite.bboxRight

    Sprite.bboxtop

    Sprite.bboxbottom

  • The expressions

    Sprite.bboxLeft

    Sprite.bboxRight

    Sprite.bboxtop

    Sprite.bboxbottom

    It's now working well! Thanks for all the help.

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