Hello,
Im writing RTS game. Im currently using this script for placing objects in grid:
public static Vector3 MousePositionSnapToGrid(Vector3 position)
{
Vector3 currentPos = position;
position.x = Mathf.Round(currentPos.x / ResourceManager.GridSpacing) * ResourceManager.GridSpacing;
position.z = Mathf.Round(currentPos.z / ResourceManager.GridSpacing) * ResourceManager.GridSpacing;
return position;
}
It works great when building has all the same scales but it goes out of grid for building that has different scale. I think that it has something to do with pivot but im’not certainly sure how to fix this issue. Have You any ideas?
There’s screen describing the problem - Imgur: The magic of the Internet
As you can see building with scale 1 and road are placed correctly while building with scale 2 not.
Regards