Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

snap to grid

/* General idea:
	
    x = floor(x / gridSize) * gridSize;
    y = floor(y / gridSize) * gridSize;
    
    floor() sets it to the beginning of the cell
    round() to the tenth place multiplied by gridSize
    ceil() to the end of the cell
*/

// example in typescript:
x = Math.round(x / gridSize) * gridSize;
y = Math.round(y / gridSize) * gridSize;
Source by www.reddit.com #
 
PREVIOUS NEXT
Tagged: #snap #grid
ADD COMMENT
Topic
Name
7+4 =