I have a sub-node (2d) in my game which should capture the mouse click coordinates and move the player sprite to them. Basically, it's a map which displays above the game window.
I have 2 questions:
1) How do I transform the coords of global mouse click captured by the node into coordinates inside the node?
2) How can I avoid capturing clicks outside of the map node without having to attach things like Area2D to it? Or is it the only way?
Here's the code:
# class member variables go here, for example:
# var a = 2
# var b = "textvar"
var begin = Vector2()
var end = Vector2()
var path = 
const WALK_SPEED = 100
# Called every time the node is added to the scene.
# Initialization here
if (event.type == InputEvent.MOUSE_BUTTON and event.pressed and event.button_index == 1):
print("Click position: ", event.pos)
begin = get_node("Panel/Node2D/Player").get_global_pos()
print("Begin: ", begin)
# Mouse to local navigation coordinates
end = event.pos - get_mouse_pos()
print("End: ", end)