How do I make grid snapping?
Could you elaborate more in what you want to achieve? Like dragging an object with the mouse and be snap programmatically? or it is something different?
yes like that.
Try to choose your desire grid lengh. Then, make your clip to have the same coordinate value as your mouse and divide it by your grid lengh. Then apply a floor to that… then multiply it by the grid lengh again…
1 Like
when the origin of an object is at the center (which is the case for Wick), i would do this:
this.x = Math.round(mouseX / gridLength) * gridLength;
this.y = Math.round(mouseY / gridLength) * gridLength;
This is the same as Jovanny’s method, except it rounds the value instead of only rounding it down, and because of this it doesn’t need to add gridLength / 2
at the end.
1 Like