Spawn object inside area randomly

0 favourites
  • 5 posts
From the Asset Store
94 Inside buildings views - Isometric view - PNG transparent - 2048x2048
  • Hello again everyone, here looking for some knowledge and help with C2.

    I am planning to add a feature (yep, planning, because I dont know if I can >_<) to my game where an instance is spawned at a random point inside an specific area.

    Per say, look at the image I attached, if the object appears or belongs to the first area it will appear inside that area only but at a random position inside of it. Then possibly, later on that same object but with different properties of course, will spawn in the second are again, in a random position, and so on. Do you know if that can that be done in C2?

    <img src="http://i40.tinypic.com/5duk9x.png" border="0" />

    Thank you all in advance! <img src="smileys/smiley2.gif" border="0" align="middle" />

  • You could define the area with the clamp expression.

    clamp(spawn.x, minimumx, maximumx)

    clamp(spawn.y, minimumy, maximumy)

  • LittleStain

    I was wondering you you could provide a capx. Newbies like me may not know how to do that.

    Please <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks a lot LittleStain ! But as says, do you have a capx by any chance to take a look?

  • Actually for this purpose you wouldn't need the clamp expression.

    let's say the desired area is a rectangle starting at x=100 y=100 and ending at x=200 y=250

    this code would do just fine:

    Every x seconds

    • system create object

    x: random(100,200)

    y: random(100,250)

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