Is there a formula for snapping objects to a hexagonal grid?
Printable View
Is there a formula for snapping objects to a hexagonal grid?
Maybe this will help.
These two events move the cursor horizontally following the mouse. This is the same code used to make a square grid cursor lock onto each tile.
X position of 'Cursor' < XMouse - 16
Set X position to X Cursor +32
X position of Cursor > XMouse +16
Set X position to X Cursor -32
These four events move the cursor vertically by 24 pixels (this is the amount needed so that it is aligned vertically with the next row of tiles above and below it.
Y position of Cursor < YMouse -12
+ XMouse > X Cursor
Set Y position to Y Cursor +24
Set X Position to X Cursor +16
Y position of Cursor > YMouse +12
+ XMouse > X Cursor
Set Y position to Y Cursor -24
Set X Position to X Cursor +16
Y position of Cursor < YMouse -12
+ XMouse < X Cursor
Set Y position to Y Cursor +24
Set X position to X Cursor -16
Y position of Cursor > YMouse +12
+ XMouse < X Cursor
Set Y position to Y Cursor -24
Set X position to X Cursor -16
Thank you, it works.
*throws Looki's one event solution into the recycle bin*
OrQuote:
These two events move the cursor horizontally following the mouse. This is the same code used to make a square grid cursor lock onto each tile.
X position of 'Cursor' < XMouse - 16
Set X position to X Cursor +32
X position of Cursor > XMouse +16
Set X position to X Cursor -32
Always
Set X position to XMouse Mod 32
Set Y position to YMouse Mod 32
Although it worked perfectly, fool -_-
I prefer something I can understand and that others can understand becuase if I finish this I will be releasing it open source.
It's really quite! easy to understand.
Hey guys,
I've been trying to create a snapping grid (32x32 square) for a mouse-controlled Active Object.
I've tried both versions of code that are listed in this thread with the same results: The Active Object always snaps back to a position near where it begins. No matter what direction or speed at which I move the mouse, it always returns to this "default" position as soon as it stops moving.
I understand both versions of the code, and I know they should work perfectly, hence why I am unsure why it mine is not.
Is there absolutely anything else I must do the the Frame, Active Object, or something else?
I've also tried using an Easy Grid with and without these versions of code with identical results.
Thanks in advance.
Oops!
I solved my problem:
I had my object set with a movement type of "Mouse"
THAT WAS BAD!