Placing a cube at the point you look at, without overlapping.

I want to place a cube a certain distance form the player and at a point defined by a raycast going from the camera.

I do a raycast that is rotated so it is following the camera’s rotation and I create a simple cube at the hit point. Now the cube is created but since its origin is in the center it is half sunk into the object it was created on.

I need it to be placed on the object I’m facing and not sunk into it. I am not sure how I’d do this since the hit normal doesn’t really fix the problem. Any ideas?

Please ask if you don’t understand the question.

It sounds like you are most of the way there. Typically you use the hit.normal to move the point up. Something like:

  var pos = hit.point + hit.normal * halfObjectHeight;

…where ‘halfObjectHeight’ is the distance from the bottom of the object you are placing to its pivot point. The value for a default cube will be 0.5 if not scaled. If it is scaled it will be 0.5 * transform.localScale.y;