Question by
codideighton1 · Oct 30, 2019 at 03:50 PM ·
2dgrid based gamegrids
Issue with WorldToCell and Tilemaps.
I have a script to give me the position of a tile where the screen is clicked but the player object is not moving to the correct position. If I click 0, 0, 0 the player will move there but every other point and it will move to a seemingly random location. Also multiple cells are showing in the console as the same point.
private void FixedUpdate()
{
// Left click - get info from selected tile
if (Input.GetMouseButtonUp(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Vector3 worldPoint = ray.GetPoint(-ray.origin.z / ray.direction.z);
Vector3Int cellPosition = -Vector3Int.RoundToInt(grid.GetCellCenterWorld(Vector3Int.RoundToInt(worldPoint)));
// Set selectedUnit to clicked location on grid
StartCoroutine(selectedUnit.setLocation(cellPosition));
Debug.Log(cellPosition);
}
}
I hope someone knows what the issue may be as WorldToCell seems to work fine for other people. Thanks
Comment
Your answer
Follow this Question
Related Questions
Tile-based Enemy AI issue 0 Answers
Delete a specific GameObject (with tag) on a Specific Vector2 Location 0 Answers
Tilemap select tile with mouse issue 1 Answer
How to drag object in GridLayoutGroup 0 Answers
Drag and Drop Problem 1 Answer