I need snapping to the nearest unoccupied grid point

I have a functional item drag and drop system but they overlap when placed on the same grid space. I've managed to make them check for an object collision, but I cant make the object snap to the nearest unoccupied grid point. If anyone knows how to help Id greatly appreciate it.
 
P

ParodyKnaveBob

Guest
Howdy, and welcome to the GMC. $:^ J

I offer not a solution, but questions to facilitate solutions.

How does your functional system work? Do you use a DS Grid for any of it? An array? Is it all based entirely on instances and screen coordinates and collision checking -- and if so, is there a separate "grid" object instance?

I hope this helps in the long run,
 
Howdy, and welcome to the GMC. $:^ J

I offer not a solution, but questions to facilitate solutions.

How does your functional system work? Do you use a DS Grid for any of it? An array? Is it all based entirely on instances and screen coordinates and collision checking -- and if so, is there a separate "grid" object instance?

I hope this helps in the long run,
Thanks for responding, I'm using the room tiles. When clicked the object x and y is set to the mouse x,y ,and when released it snaps to the nearest room grid position. But they overlap if placed on top of each other. I need the dragged item to snap to a different grid point if the one its released on is occupied
 

Let's Clone

Member
I'm not entirely certain of what you're trying to do, but it could be as easy as (mouseX div cell_size). This will give you the x-coord of the grid-space based on the x-position of your mouse.

After getting the X/Y you can check the grid to see if that space is available. If not then you can run a loop to check the adjacent spaces.
 
Top