Grid system maths

So to be sure I am in the right headspace.
We first made a grid system that was already divided by the vector positions

But since we want them to be visually on the center of each box grid, we needed to introduce cellSize so each position is now newCellposition = position * cellSize.

But since we want our mouse to be able to distinguish each cell position in normal distance apart, we just have to divide the cellSize again. (position * cellSize) / cellSize = originalCellSize

Hi @Napmi! Welcome to the community

I think you’re there.

Without cellSize everything is considered to be 1. So, if we click on position (15,12) we have clicked on the cell at 15,12.

Now, we want our cells to be bigger than 1, so we set it to 2 (for instance). Now if we click on (15,12) we are no longer clicking on cell 15,12 because the cells are bigger. So, we divide our position by cellSize (round it) and we get 8,6. So, we clicked on cell at 8,6.

If we have the cell position (8,6) and we want to determine the world position we multiply it by the cellSize to get the center of our cell in world space: 16,12. This is not where we clicked, but we must remember that cells now have a size of 2, so both 15 and 16 will be the same cell

Hope this get you in the correct headspace. I may have confused things more. Sorry

2 Likes

Sound about right ! Thanks @bixarrio
I think i was missing the term “world position” in my initial explanation to better describe things.

Yup, the only thing the cellSize is doing is just making the grid more adaptable, without it the only option is for each grid position to have a size of 1 world unit, which depending on how big are your visual assets is probably too small like it is in the assets used in the course.
Then yup that value is included in the calculations to and from World Position > Grid Position

1 Like

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

Privacy & Terms