- Home /
The question is answered, right answer was accepted
Lock snaped position at sides of the cube
So far I have a grid and the cubes snap and align nicely, the problem is that the cube which I am raycasting, snaps in the air, diagonally of the cube, the cubes snap to the sides as well, but I want to remove this air/diagonall snapping, what I tried was to put tags on terrain and blocks so it avoids the "air" but actually it still touches the edges of the cube and "hangs" in the air,
Answer by crohr · Jun 08, 2015 at 06:37 PM
Here is a similar question that I answered previously that I believe is what you want as well: http://answers.unity3d.com/questions/975675/help-finding-out-which-side-of-a-cube-a-raycast-hi.html
The basic idea is to figure which side the Raycast hit was on and modify the blockCursor transform to be offset using the position of the object hit using the hit.normal property.
I tried if(hit.collider.tag == 'Solid') { blockCursor.transform.position = hit.transform.position + hit.normal; }
But its not working, maybe I am not using it as intented?
That should be correct if your cubes are 1 unit in length. What was happening when you tried to use hit.normal
When I use
if(hit.collider.tag == 'Solid')
{
blockCursor.transform.position = hit.transform.position + hit.normal;
}
The blockCursor repositions itself at the edge of the map
Follow this Question
Related Questions
Snapping models 3 Answers
turning on x and y axis for turret but not using lookat? 1 Answer
Snap Objects when Spawning 0 Answers
Editor Handles Vertex Snap not working on script's object. 0 Answers
Rotational Surface Snap in Unity Editor? 0 Answers