- Home /
GridLayout.WorldToCell how does it work?
I'm having trouble understanding how it converts a world position to a cell position. What is the difference between world position and cell position?
Answer by hexagonius · Nov 24, 2018 at 01:16 PM
This has to do with spaces. The world space is where every root gameobject is positioned in the the viewport. As soon as you add a child gameobject to any of those it's positioned relative to that gameobject, called local space. Now a GridLayout has grids and each grid is basically at a different local position to its gameobject while a point within a grid cell is at the local space of that cell. Now WorldToCell converts a position, e.g. the player somewhere in the scene, into the grid telling the cell the position fit into. The fact that the return value is a Vector3int tells me that it's the cell, not the position within that cell as that would be not accurate.
I'm a little lost on your explanation. Here is a picture of my objects transform.position and me converting that to a cell position. I don't understand how the x value went from 0.5 to -1.
[1]: /storage/temp/128267-unity-help-3.png
Ok so I figured it out, for some reason I had my tilemap's x position set to 1, and it was skewing the x value to a position that didn't make sense to me. Thank you for your answer, I feel like i'm understanding it more now!