Previewing and placing a cube at wrong Y coordinates

When I try to place a building, it previews and places the building in a way that the half of the cube will be placed below the floor. (At 0.5 Y coordinate, where height of the building is 1.)

I have solved that issue by adding half height of the building to the hit.point by using the following line:

Vector3 positionToPreview = hit.point + hit.normal * (building.transform.lossyScale.y / 2);

Does anyone have an idea how could I fix that issue using the Unity interface?

Hi, maybe you can change the position of the building in the building preview. Move the building up within the building preview prefab.

I tried doing that at first. However the position of the building is set programmatically based on the hit point. Because the raycast hits the floor at Y coordinate 0, the building will be placed accordingly.

Empty gameobject with the mean 1/2 up or change the mesh pivot point.

In the building preview prefab you can modify the children, not the parent. That way the offset exist but the parent is what gets set to zero.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms