# Aligning a gameObject to position and normal of another gameObject inside Unity

So I am instantiating a GameObject (the one with cities and trees in the image below) and trying to align it to a hex tiles on a Sphere.

So after I instantiate the gameObject, I ray-cast to get it aligned to the tile normal and tile position but its always a slight offset.

    int random = Random.Range(0, middleIceTiles.Count);
GameObject tile = middleIceTiles[random].getTileGameObject();
HexCity cityObj = new HexCity(city, "city-" + middleIceTiles[random].getTileName());
GameObject cityDummy = Instantiate(cityObj.getCityObj(), tile.transform.renderer.bounds.center + new Vector3(0,0.2f,0), Quaternion.identity) as GameObject;

//do a raycast here
RaycastHit hit;
Vector3 normal = Vector3.zero;
if (Physics.Raycast(cityDummy.transform.position, cityDummy.transform.up * (-1.0f),out hit, 25.0f))
{
if (hit.collider.gameObject == tile.gameObject)
{
Debug.Log(" HIT SNOW TILE CITY " +tile.name+ " TILE TEXTURE " +HexTextureInfoDict[tile.name]);
normal = hit.normal;
}
}
cityDummy.transform.rotation = Quaternion.FromToRotation(Vector3.up, normal);


So I am getting a random hex tile on the sphere. Then instantiating the cityObj to the tile position. Doing a raycast from the cityObj to the tile to get the tileNormal and orienting it to the tile.

So on each level load, the city gets placed on a random hex tile. But currently, the orientation as well as the position is not exact and always at some offset position from the current tile.

What am I doing wrong here? Is there any other way I can achieve this?

Also, one possible solution is to snap the vertices of the hex gameObject to the hex tile itself. So essentially the 6 vertices of the hex tile has to match the 6 vertices of the hex gameObject. Is this possible? I have never dealt with meshes information of gameobjects inside unity before so I am not sure if this would work?

 Mesh TestMesh = testTile.GetComponent<MeshFilter>().mesh;