How to get input event's position relative to world origin when a camera2D is used for zoom?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mil

In my scene, I have a Camera2D and a node that reacts to touch events. The node uses node.get_viewport_transform().xform_inv(event.position); to translate the incoming event’s position from screen space to world space. So far this works perfectly. Things happen in the game world exactly where I touch the screen.

I then set the Camera2D’s zoom property to Vector2(3.0, 3.0). The view expands like I would like, but the change doesn’t affect the viewport’s transform. The event’s translated position is as if there was no zoom. Camera2D doesn’t have a method for projecting or unprojecting points.

I can’t figure out a way to find an event’s global position when using a camera with a zoom.

I need to deal with events from multiple touch points, so the helpers for finding global or relative mouse positions and polling for pointer information instead of processing events aren’t available.

:bust_in_silhouette: Reply From: barbaros

when you zoom the camera try setting the viewport transform to the same zoom, im not sure but it might work

:bust_in_silhouette: Reply From: mil

The correct way to do this is (probably) by using Node.make_input_local(event);.

This leaves me with no way to translate plain screen coordinates into world (or relative to a node) space without creating a dummy event to do the transformation with, but fortunately I don’t need to do that right now.

For the node that needs to keep doing things when there are no new events but the cursor is still active (meaning your finger is against the screen but perfectly still) because the camera can move around, I’ve resorted to keeping a reference to an old untranslated event and making new ones with the above method inside the node’s _process().

In the end there was no need to mess around with transforms.