GridSystem: FloorToInt instead of RoundToInt

In “public GridPosition GetGridPosition(Vector3 worldPosition)”:

Using RoundToInt() does not make sense. When the mouse pointer points at upper half of the grid cell then the next grid x and z are returned. Using FloorToInt() solves this.

2 Likes

Units are always arbitrary, you can use whatever makes most sense to you, both methods work just fine.
Remember the player is never going to see that, for them one grid is one grid, regardless of the underlying Vector3 position.

Are the small markers displayed for the grid supposed to be the centre of the cells (in which case RoundToInt would be correct), or the bottom left corner of the cells (in which case FloorToInt would be correct)?

Edit: From the following couple of videos, it seems that the marks represent the centres of the cells, therefore the RoundToInt would seem to be the right method to use.

In the course yes I use RoundToInt and the visual shader is made so each grid position is visually in the center of each visual grid.
But like I said it’s all arbitrary, you can easily use a different visual for the floor, or add some offset to the shader, and use Mathf.Floor or Mathf.Ceil. As long as you use it consistently then every method will work the same.

1 Like

Thanks for the replies. It was indeed me, not understanding that the grid cell text is at the center of the grid cell. Thanks for the clarification.

(!) For others, I had to manually add the displacement in the ShaderGraph, which was explained in the training during one of the earlier lessons.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms