Context: I'm implementing Gamepad input and trying to simulate a mouse cursor. I have Area2Ds in my scene for objects I want to be able to interact with the simulated cursor (ex. hover/click). I'm trying to get an Area2D in the scene to follow the mouse cursor so I can get AreaEntered/Exited events when it overlaps those objects. My simulated mouse pointer is a Control with a TextureRect, on a CanvasLayer.
I've tried a bunch of methods on the pointer Control, like (C#):
myArea2D.GlobalPosition = myPointerControl.GetScreenTransform().Origin
myArea2D.GlobalPosition = myPointerControl.GetGlobalTransformWithCanvas().Origin
But none of these work. My Area2D follows the motion of the cursor (so the scale is right) but is offset by a large amount that seems to change depending on the position of the Camera2D.
In general I want a CanvasToWorld function I can use like this to translate from Canvas coordinates to World coordinates:
myNode2D.GlobalPosition = CanvasToWorld(myPointerControl.GlobalPosition);
Does anyone know how to do this?