# How can I snap to hex tile centers in world x,z coords?

I was able to find the positions of the center vertices of the 6 hexes surrounding my first hex tile at (0,0) :

(13.5, 7.794228)

(0, 15.58837)

(-13.5, 7.794228)

(-13.5, -7.794228)

(0,-15.58837)

(13.5,-7.79)

I’m just not sure where to go from there.

I hope i have understood you correctly
This is just a modified version of my square grid, seing as a hex grid can be achived with two square grids with 0.5 offset

public static float gridSpacing = 1f; // Distance between hex centers
public static Vector3 GetHexPosition (Vector3 convertPosition)
{

float newx1 = Mathf.Round (convertPosition.x / gridSpacing) * gridSpacing;
float newz1 = Mathf.Round (convertPosition.z / gridSpacing) * gridSpacing;

float newx2 = Mathf.Round (convertPosition.x / gridSpacing) * gridSpacing + gridSpacing/2;
float newz2 = Mathf.Round (convertPosition.z / gridSpacing) * gridSpacing + gridSpacing/2;

Vector3 result1 = new Vector3(newx1, 1, newz1);
Vector3 result2 = new Vector3(newx2, 1, newz2);

if(Vector3.Distance(result1,convertPosition)<Vector3.Distance(result2,convertPosition))
{
return result1;
}
return result2;

The code i use to call this function

RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);

if (Physics.Raycast (ray, out hit))
{
gridPos = GetHexPosition(hit.point);
this.gameObject.transform.position = gridPos;
}

IT is attached to the semitransparent object i use to show what tile are marked, with a ray colliding with a flat terrain