- Home /
Drag n Drop Cube To Snap In Place - Grid
Hello,
I have a cube on my scene that has the Drag Rigidbody, so I can move it around the scene with the mouse. On the floor of my scene is a grid (which is just a material). It is possible to make the cube snap into the grid when the user lets go of the cube (A drag n drop snap).
Here is a screen shot of my scene normally: http://olliejones.com/gridsnap.png
I was thinking that maybe by placing Empties within each grid, will return the empties position value in which the cube could snap to ... surely?
Or is there a way to have the grid interactive - instead of using a material, Unity actually places a mathematical grid down...
Thanks
Answer by Proclyon · Nov 18, 2010 at 03:01 PM
You will have to write a special handle for the mouse events.
Maybe something like this can help in pseudo-mush.
if (mouse dragged right) { increment object location with distance of one tile to absolute right }
if (mouse dragged left) { increment object location with distance of one tile to absolute left }
absolute values will cause great suffering though if you rotate the grid of course. So do relative values instead if you plan on changing the grid/tile design
I don't have the option to write you a whole sample now so I hope I can get the idea through quickly enough whilst rushing this text.
Good luck and regards!
Your answer
Follow this Question
Related Questions
Snap to place 1 Answer
Drag and Drop 3D Objects around in 3D space and snap to other 3d locations with logic card shuffling 2 Answers
DragRigidbody behavior attached to multiple rigid bodies causes problems 1 Answer
how to right click OnMouseDrag C# 2 Answers
Dragging an Object with mouse in 2D 1 Answer