How do I spaw random objects

0 favourites
  • 11 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hi guys,

    Is there somebody that can tell me how i build a game where multiple object randomly fall down from the top of the layout on random places (but on top of the layout of course)

  • create a Sprite and add a bullet behaviour

    Event

    system > on start of layout | objSprite > destroy

    system > every 2 seconds | system > create objSprite on layer=0; x=random (WindowWidth); Y=-30

    add action > objSprite > set Bullet angel of motion=90

  • Thanks!

    i'll give it a try, but is it possible this way that a sprites will be half on the screen at the sides?

  • in this case yes

    to change that you could make a more precise random number

    random (30,(WindowWidth-30))

    Now the number starts at 30 and ends 30 pixels left of your layout.

  • Thanks!

    You made my day!

  • So the game is working pretty fine but i am now struggling with something new.

    I want my objects to be spawn pretty fast (random(0.2, 0.7)) and the bullet motion pretty slow, but now sometimes the sprites are overlapping.

    Is there a way to set the nextspawn at least (for example) 30 pixels to the left of right?

  • Here you have, as almost always, different options

    make a loop

    so you don't spawn directly and run a loop where the loop checks if the new spawn point is greater than 30 (check it against a variable you set when an object gets created)

    Or you could make it with an array and spawn points (invisible sprite objects where the new objects get spawned) so instead of pixels you spawn them from the boxes - this is very useful if you want the objects get spawned evenly across the screen.

    Also with a loop, but here you can decide very precisely what you want to do.

    Or you could make a small random number and multiply it by 30 (still you need a loop to check where the last spawn happened). Th long version would look like this floor(random (0, windowWidth/30))*30

  • "Object": is overlapping "Object" > "Object" destroy.

    Alternately: > set "object" x:self.x+somedistance (Ie self.x+32)

    No loops, variables, or arrays. =) Often used for top down SHMUPs.

    Also, don't forget to destroy your objects if their Y becomes greater than viewport:bottom! =)

  • Davemon

    oops forgot about the "is overlapping" -

    that's definitely the easiest one (if it's ok that som bullets are skipped)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you guys!

    I will try them all and see which one fits best for my game!

  • Remember, "on overlapping" is just a condition. =) You can give it many actions from there, including re-positioning.

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