I'm using mouse input to move the player from where they are to where the mouse position is relative to the cell on a tilemap. However I found when I click on a point of the tilemap, the z coordinate for it is -10. This has led to me to dealing with a work around of just resetting the player's z coordinate every time they are moved. I was wondering why this is the case and if there is a way to fix this so I don't have to reset the z coordinate every time. Player starts at (0,0,0) in world position.
Moving the player 2 hexs to the right should result in (2,0,0) but instead returns (2,0,-10)
Here is the code for player movement:
var screenPos = Input.mousePosition; var worldPos = Camera.main.ScreenToWorldPoint(screenPos); var coordinate = grid.WorldToCell(worldPos); Debug.Log(coordinate); //resetting the z coord transform.position = grid.CellToWorld(coordinate); Vector3 position = transform.position; position.z = 0; transform.position = position;