How do I get the coordinates of a tile?

Godot Version

Godot v4.2.2.stable

Question

I’m trying to get the coordinates of a single tile when it is clicked on. The code below returns coordinates like Click at: (8696, 5544). But I want to get the vector coordinates like (0,1). I’ve looked through the documents but can’t seem to find how to do that. When I hover over it in the tilemap editor I can see those coordinates on the bottom left.

extends TileMap

func _input(event):
	if Input.is_action_just_released("Select"):
		print("Click at: ", map_to_local(event.position))

Also, is there a way to restrict how big the tilemap is? Adding a boundary or only creating one of a specific size? I’m trying to create a basic tic-tac-toe, so I want to be able to apply data (whether it contains an X or an O) to a 3x3 grid.
Sorry if I’m missing something super obvious.

tilemap.local_to_map(event.position)

Or just divide by tilesize if tilemap is not offset

1 Like

Thank you! I completely missed the obvious haha

1 Like

You can just not apply data for tiles outside of the size you want (in this case 3x3) Once you have the tilemap in place you can call get_used_rect() on the tilemap get an area where the map it occupying.

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