Object Moving - Grid Based

0 favourites
  • 4 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • I want to move , drag and drop, an object in a grid based pattern..need help

  • Real easy to do. Just needs a little math. So suppose your grid is based on 16x16 sized squares. So if a block is anywhere from pixel (I'll just be talking about horizontally so the x-axis but the same will apply to the vertical Y-axis) 0-15, it will be in grid 1 and if it is in 16-31, then grid 2 and so on. So lets pick a pixel location say at x position 17. Take that number 17 and divide by the size of your grids which is 16. 17/16 = 1.0625. Now we want to use the floor fuction on that number so the floor(1.0625) = 1. Now multiply your new number 1 by the size of your grid which is...16! And you get 16. So any location from 0-15 will become 0, any location from 16 to 31 will become 16 and so on.

    Here's some more math stuff you can play around with.

    scirra.com/manual/126/system-expressions

  • amazing answer thank you really much

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • can you post an example? maybe i got it wrong mhm dunno how to do it with specific objects e.g. move, and let workers run normally

    edit: did it, just seemed like nothing happened, my grid is too small to see something thank you =)

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