I instantiate an object and snapping its position to a grid, the problem is that i add values to the mouse position to make it snap. I want the object to stay in the middle of the mouse while still snapping to the grid but i can’t find a solution.
Here is the code where im adding the value so it snaps.
This is not possible. If your object is in the middle of the mouse, then it cant be snapped to the grid (at all mouse positions) . Maybe what your trying to do is make it snap to the grid, only when its a certain distance away (have a jump threshold) that way it could stay in the middle of the mouse until it was almost lined up with the grid, and then snap to the grid. Is that what your after?
Hey LeftyRighty, thanks for the response but I have solved this yesterday. As for people looking this up in the future, the solution can be found on my Unity Answers Question since I figured theres a lot of empty posts on this topic which is usually overly thought out.
As for impkementing the grid, the game is procedural generated in chunks, each grid is a 1x1 to keep things simple. I would simply raycast and do the usual. The only difference is using a different approach to the rounding.
Its entirely configurable as long as your snapValue in my script provided is correct.