How do I make objects spawn on grid?

0 favourites
  • 7 posts
From the Asset Store
Grid - snap to grid
$1 USD
80% off
Snap to visible grid - perfect solution for any game genre
  • I have multiple objects falling down from the sky at different rates. However, I never want one to overlap or spawn on the other and always want them fall in a moving grid. For example, imagine something like a tic-tac-toe board on a 20 x infinite grid and there are Xs and Os scattered throughout.

    I'm using "Create object" to spawn objects and "Bullet gravity" to set speed.

  • The way I make grids, is to set the position in intervals of 20 (or any number you want), using this:

    Sprite;

    Set X to : (round(Sprite.X*0.05))*20

    Set Y to : (round(Sprite.Y*0.05))*20

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm... the objects are now spawning not from the sky but from the last object and also don't randomly spawn along the X axis.

  • Wait I think I got it:

    X: random(100,600)

    Y: -250

  • Darn. too systematic for the last code i put in. I need it to randomly spawn in any of the grid buckets and not just the same distance each time.

    X and Y between ranges but within grid

  • The way I make grids, is to set the position in intervals of 20 (or any number you want), using this:

    Sprite;

    > Set X to : (round(Sprite.X*0.05))*20

    > Set Y to : (round(Sprite.Y*0.05))*20

    What about this for Y?

    random(round(-100*0.05)*150,round(-600*0.05)*150)

  • Set X to : round(sprite.X/gidsize)*gridsize

    So for a 32 grid: round(sprite.X/32)*32 . YOu can use the same formula for snapping stuff to the Y axis too.

    To make them "fall" on grid increments, use a move +Y:gridsize

    Any other movements, have only at the gridsize, and it should never need to be set on the grid again.

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