# Instantiation on side of cubes, relative to placment.

I made a cube script that instanceates cubes next to each other, minecraft style.
I am wondering if there is any way I can take a turret and if I place it on the right side it will be instantiated with the bottom of the turret connected to the right side. and the same for all sides. I have been trying to make this work I thought that I could use 6 diffrent plane colliders but it wont work because I can only use 1 unit cubes from unity, 'I cant import a 1mx1m cube from max because they are too small.
Its like this, .

When I want it to be like this.

Here is the code to help, Thank you. `using UnityEngine;
using System.Collections;

``````public class ConstructionSpacestation : MonoBehaviour
{
public GameObject Builder;

// placeholder for what you see on the screen.

private Transform actualBlock;

void Update()
{

if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;

if (Physics.Raycast(ray, out hit, 2000))
{

Vector3 position = hit.point + hit.normal * 0.5f;

position.x = Mathf.Round(position.x);
position.y = Mathf.Round(position.y);
position.z = Mathf.Round(position.z);

GameObject Placement = Instantiate(Builder, position, Quaternion.identity) as GameObject;

}
else
{
Debug.Log("nothing");
}
}
}
}`
``````

For a cube, you can calculate the center of the hit face like this:

``````Vector3 position = hit.transform.position + hit.normal * cubeSize/2;
``````

You should also calculate the rotation of the new object so that it would align to the face normal:

``````Quaternion rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
``````

Use this rotation instead of Quaternion.identity, which means “no rotation”.

Your code could be like this:

``````void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 2000))
{
// it's better to find the center of the face like this:
Vector3 position = hit.transform.position + hit.normal * 0.5f;
// calculate the rotation to create the object aligned with the face normal:
Quaternion rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
// create the object at the face center, and perpendicular to it:
GameObject Placement = Instantiate(Builder, position, rotation) as GameObject;
}
else
{
Debug.Log("nothing");
}
}
}
``````