I press at the same time with 2 fingers. I want it to give 2 vectors, but it gives one.

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

but when I try to press with multiple fingers it returns a one vector
For example, I press at the same time with 2 fingers. I want it to give 2 vectors, but it gives one.

:bust_in_silhouette: Reply From: r.bailey

I will post a link below, not sure if this will help you, as I have never tried to implement a multi-touch functionality in Godot. It would appear that some of this is mobile only, but that might be what you are looking for. Just hoping that this information might help you or guide you in the right direction.

GodotEngine - MultiTouch

:bust_in_silhouette: Reply From: Wakatta

If you only want 2 pointers and no more

var pointer1 = Vector2.ZERO
var pointer2 = Vector2.ZERO

func _input(event):
    if event is InputEventScreenTouch:
        if event.is_pressed():
            if event.index == 0:
                pointer1 = event.position
            elif event.index == 1:
                pointer2 = event.position
        else:
            if event.index == 0:
                pointer1 = Vector2.ZERO
            elif event.index == 1:
                pointer2 = Vector2.ZERO
    elif event is InputEventScreenDrag:
            if event.index == 0:
                pointer1 = event.position
            elif event.index == 1:
                pointer2 = event.position

Though the recommended way is to store your inputs in a dictionary or array.

var touches = []

func _input(event):
    if event is InputEventScreenTouch:
        if event.is_pressed():
            touches.append(event.position)
        else:
            touches.remove(event.index)
    elif event is InputEventScreenDrag:
        if touches.has(event.index):
            touches[event.index] = event.position

THANK YOU SO MUCH

federal | 2021-08-04 06:24