Godot 4.3
Hello All,
I am very new to godot, and I was trying to use the gridmap node. I was trying to see the coordinates of the gridmap as I was painting tiles, but I was unable to find any way to add that. I ended up trying to make a plugin to see the coordinates. Using some AI assistance, I managed to get to a point where I can see the mouse position, but it does not allow me to see the gridmap coordinates yet. I was wondering if anyone knew the solution to this problem, or if there was an easier way to find the coordinates to the gridmap.
Here is the code that I have so far:
[@]tool
extends EditorPlugin
var grid_map = null
var label = null
func _enter_tree():
var selected_nodes = get_editor_interface().get_selection().get_selected_nodes()
if selected_nodes.size() > 0:
grid\_map = selected\_nodes\[0\]
if grid\_map is GridMap:
label = Label.new()
label.set\_text("GridMap Coordinates:")
add\_control\_to\_container(CONTAINER\_CANVAS\_EDITOR\_BOTTOM, label)
print("Plugin initialized")
func _exit_tree():
if label:
remove\_control\_from\_container(CONTAINER\_CANVAS\_EDITOR\_BOTTOM, label)
label = null
print("Plugin exited")
func _process(delta):
var selected_nodes = get_editor_interface().get_selection().get_selected_nodes()
if selected_nodes.size() > 0 and selected_nodes[0] == grid_map:
var mouse\_pos = get\_viewport().get\_mouse\_position()
var local\_pos = grid\_map.local\_to\_map(Vector3(mouse\_pos.x, mouse\_pos.y, 0))
var grid\_pos = grid\_map.map\_to\_local(local\_pos)
print("GridMap Coordinates: (%d, %d, %d)" % \[grid\_pos.x, grid\_pos.y, grid\_pos.z\])