|
Hi - i know there are several questions like this, but none of them have a conclusive answer, and the only one that i could see and answer to has a broken link, in french, so i can't see it: http://answers.unity3d.com/questions/204483/create-grid-and-snap-rigidbodies-to-grid.html anyway, I have a 2D sprite based game, where you click on the objects you want to choose from the HUD and they spawn in the play area, I have a drag rigid body script on them and it works fine, no problems. However, i now think it would be better if the drag rigid body script worked in increments, i would have a grid on the background, and the drag wouldn't be smooth, but would snap into the positions, each equally separated. One way i could think of would be to put empty game objects on each point with a trigger area, and add a script on each trigger to say: etc, BUT i think this is extremely complicated as every level will have a different shaped grid, and i don't want to have 30 triggers with scripts and have to set them up each level.. would there be a better way to go about this? thanks in advance, by the way if there are any code samples posted, could they be in JS please.. still need to get round to start programming in C :p
(comments are locked)
|
|
This is my full implementation of Click and Drag and Snap to Place. The Snapping bit takes place in the OnMouseUp section, basically, find the center of each slot on the grid, find the location of your Object and subtract from its position to get it to the closest center. sorry for the late reply, i ended up going in a different direction and not implementing this at all, now i haven't tested your script but the logic makes sense, thanks for the answer, this may come in handy in the future :P :)
Jun 30 '12 at 10:15 AM
ratboy
(comments are locked)
|
