0 votes

I want make a controller about mutil touch.(three fingers touch screen as meanwhile)
What I want to get second finger's position when I using function"InputEventScreenTouch::get_position", but I only got first finger's position and also "index" is 2.
I`m so sorry for my English,but I must to searching some solution for this problem.
Thanks very much.

Godot version 3.5.1
in Engine by (15 points)

1 Answer

+1 vote
Best answer
var first_pointer_position
var second_pointer_position
var third_pointer_position

func _input(event):
    if event is InputEventScreenTouch:
        match event.get_index():
            0: 
                 #first pointer
                 first_pointer_position = event.position
            1: 
                 #second pointer if any
                 second_pointer_position = event.position
            2: 
                 #third pointer if any
                 third_pointer_position = event.position

Now you could create a var in global space for each pointer position and assign them each in their designated block like the above code or you could do the following

var pointers = {}

func _input(event):
    if event is InputEventScreenTouch or event is InputEventScreenDrag:
        pointers[event.get_index()] = event

Then access it like this

#Second pointer position 
pointers[1].position

You can even take it a step further and use an enum to avoid confusion

enum {FIRST, SECOND, THIRD, FORTH}
pointers[THIRD].position
by (6,876 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.