x


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#.

more ▼

asked Jul 03 '10 at 08:07 AM

Jason Hamilton gravatar image

Jason Hamilton
445 68 73 80

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
more ▼

answered Jul 03 '10 at 09:21 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5087
x1038
x268
x46
x36

asked: Jul 03 '10 at 08:07 AM

Seen: 2897 times

Last Updated: Jul 03 '10 at 01:29 PM