I’m making a game that has you placing objects with the mouse on a hexagonal tilemap, and I would like to be able to snap the objects to the center of the tile they are being placed on. I’m having difficulty calculating the positions to snap to, however. Does Unity provide a way to do this?
Update: I found it; the center point of the tile the mouse is over can be found using these lines of code:
Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));
Vector3Int mousePosTile = tilemap.WorldToCell(mousePosWorld);
Vector3 mousePosTileCenter = tilemap.GetCellCenterWorld(mousePosTile);