- Home /
Infinite 2D placement grid
Hey, I'd like to make a grid, in the Y and Z axis. The grid needs to be invisible and each corner point has to be a clip to thing for a cube, so the user can make a track like a level builder. How do I do this? Preferably in Javascript not C#.
Answer by Mike 3 · Jul 03, 2010 at 09:21 AM
the easiest way i would think is to do something like this when you're moving it:
var gridSpacing = 2.0; // put this at the top of your script
//move the object like normal, then clamp it with the code below (if you want this in the object's script, change yourObject to transform)
var position = yourObject.position; position.x = Mathf.Round(position.x / gridSpacing) gridSpacing; position.z = Mathf.Round(position.z / gridSpacing) gridSpacing; yourObject.position = position;