0 votes

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.

Note:
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.

Godot version 3.2.3
in Engine by (19 points)

2 Answers

0 votes
Best answer

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.

by (19 points)
0 votes

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

by (52 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.