Isometric hovered cells (in a tile map) difficulties

Godot Version



I’m fairly new to Godot, I played around with 3 back a long time ago and now I’m trying out 4. I’m essentially a beginner at this point.

I’m working on figuring out isometric tile maps and individual tile interaction. I watched a tutorial and used the docs to figure out get_cell_tile_data and get_custom_data. I have a simple three-layer setup where the tiles have some custom data.

When the mouse hovers a tile, I’d like to report the data for the layers- i.e., if a cell that only has a tile on layer 0, only layer 0’s data should be reported. If a cell has a tile on layer 0 and layer 1, then both layers should be reported. This quick video shows it better:

The system kind of works (it works great on cells with one or two layers), but not three. I have three questions-

  • How can I get the “stack” data for a cell with three layers?
  • Why is the hovered_cell so jumpy when there’s more than 1 layer?
  • How can I get the coordinates of a hovered cell?

The first two questions can be summarized as- “what am I doing wrong?” and the third is more “what am I looking for in the docs?”

The code is quite simple, I have a Control node with a TilePos label child with this script:

extends Control

func _process(delta):
	var tilemap = get_parent().get_node("TileMap")
	var hovered_cell = tilemap.local_to_map(tilemap.get_local_mouse_position())
	var data = tilemap.get_cell_tile_data(0, hovered_cell)
	var data1 = tilemap.get_cell_tile_data(1, hovered_cell)
	var data2 = tilemap.get_cell_tile_data(2, hovered_cell)
	if data or data1 or data2:
		var layers_with_data = [data, data1, data2]
		var label_text = ""
		for layer in layers_with_data:
			if layer:
				label_text += str(layer.get_custom_data("Name")) + "\n"
		$TilePos.text = label_text

	if !data and !data1 and !data2:
		$TilePos.text = ""

I know a file is worth a million words, so here’s my file:

(Sorry, I can’t upload it directly yet.)

I appreciate any advice, help, or pointers here, I’ve been trying to find answers in the docs for a couple hours now and I think I’m officially stuck