In a FPS i'm trying to instantiate cube like the old good minecraft. The problem is that the first cube i instantiate on terrain got y=0 but half of that cube is underground ... HowAll my cube prefab are 1x1x1.
How to solvefix this problem ?
void BuildBlock(GameObject block)
{
if (Physics.Raycast(shootingPoint.position, shootingPoint.forward, out RaycastHit hitInfo))
{
if (hitInfo.transform.tag == "Block")
{
// Instance over other cube
Vector3 spawnPosition = new Vector3(Mathf.RoundToInt(hitInfo.point.x + hitInfo.normal.x / 2), Mathf.RoundToInt(hitInfo.point.y + hitInfo.normal.y / 2), Mathf.RoundToInt(hitInfo.point.z + hitInfo.normal.z / 2));
Instantiate(block, spawnPosition, Quaternion.identity, parent);
}
else
{
// Instance on terrain
Vector3 spawnPosition = new Vector3(Mathf.RoundToInt(hitInfo.point.x), Mathf.RoundToInt(hitInfo.point.y), Mathf.RoundToInt(hitInfo.point.z));
Instantiate(block, spawnPosition, Quaternion.identity, parent);
}
}
}