Help: Local Map Position (code confusion)

Godot Version

4.3.Stable

Question

Hello,

I am confused to why two functions are giving me two different results.

The functions are meant to give the coordinates of a mouseclick on a grid layer.
Only the second function gives the correct coordinate.

Could someone help me understand what exactly is wrong with the local position in the first function?

func _input(event):
	if event.is_action_pressed("select"):
		var local_coordinate = to_local(event.position)
		var map_coordinate = local_to_map(local_coordinate)
		print("coordinate: ", map_coordinate)
func _input(event):
	if event.is_action_pressed("select"):
		var local_coordinate = get_local_mouse_position()
		var map_coordinate = local_to_map(local_coordinate)
		print("coordinate: ", map_coordinate)

Thank you for your Help.

common error to use to_local/to_global without setting regard of what.
Personally I don’t rely on event position, better use:
map_node.local_to_map(map_node.get_local_mouse_position())

1 Like