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:
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:
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
asked May 03 '12 at 06:07 PM
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.
answered Jun 02 '12 at 03:24 PM