Topic was automatically imported from the old Question2Answer platform.
Asked By
Corruptinator
Hello! I was trying to get the global position based on where the finger has touched on a mobile touchscreen, somewhat similar to the function: get_global_mouse_position() where the mouse global position is captured. I thought this was done by using this code:
func _input(event):
if event is InputEventScreenDrag:
touch_position = event.position
The touch_position represents the Vector2() coordinates based on the event.position. Unfortunately though this only captures the position the finger is touching on the screen. Say that my resolution screen size is set at 400x224 pixels then I can only get the position in that range such as 345x120 or 20x200 pixel position. is there a better way to get the global position capture based on the position of the touchscreen resolution limit?
Unfortunately though this only captures the position the finger is touching on the screen.
I’m not certain 100% what you’re asking for.
Do you want a more precise location of the finger touch?
Is the location you get not accurate enough?
Do you want to require that the user make more accurate finger placement?
It took me quit a while to figure it out. So i hope it will help you save some time.
Basically this solution is is the same as get_global_mouse_position(). But that function cannot be used when you are working with multitouch inputs.
Is this supposed to work when using a camera2D? I’m getting completely different coordinates with to with get_canvas_transform().xform_inv(event.position) than I am with get_global_mouse_position()
Ben Nicholl | 2020-03-19 03:32
For anyone who has this problem, this works in the cases where event.position is returning a vector relative to the viewport and you need the global position of it:
I still can’t find a solution to extract values where event.position == get_global_mouse_position().
I’ve added the event to the player and called the player on a map, but I can’t get the same value. I’ve tried all your combinations… but nothing