truePos.x = Mathf.Floor(target2.transform.position.x / gridSize) * gridSize; truePos.y = Mathf.Floor(target2.transform.position.y / gridSize) * gridSize; truePos.z = Mathf.Floor(target2.transform.position.z / gridSize) * gridSize; code example
Example 1: unity round vector 3 to nearest integer
//Converts a Vector3 to a Vector3Int by doing a Round to each value.
Vector3Int.RoundToInt(Vector3)
Example 2: round vector3 unity
vector3 = new Vector3(1.23243f, 2.213124f, 12.4123f);
var roundedVector3 = vector3.Round(1);