How multi touch works on android platform.

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

Hello. I am new in godot and recently I created project , prototype for twin stick shooter for android. Both analogs woks well. One of them is responsible for movement direction and second for shooting and shooting direction. They work good when I use one of them but when I want use both touchscreen work like with one touch. I think its a problem with index of event. But I dont know how it work exacly can someone help me ?

There is a code for the first analog :

extends Sprite

const RADIUS = 64
const SMALL_RADIUS = 32

var stick_pos
var evt_index = -1
var test = -2

func _init():
	stick_pos = position
	
func _input(event):
	if event is InputEventScreenTouch:
		if event.is_pressed():
			if stick_pos.distance_to(event.position) < RADIUS:
				evt_index = event.index
				print(evt_index)
		elif evt_index != -1:
			if evt_index == event.index:
				evt_index = -1
				print(evt_index)
				$Small.position = Vector2()
				$"../".stick_vector = Vector2()
				#$"../".stick_angle = 0
				$"../".stick_speed = 0
				
	if evt_index != -1 and event is InputEventScreenDrag:
		var dist = stick_pos.distance_to(event.position)
		if dist + SMALL_RADIUS >RADIUS:
			dist = RADIUS - SMALL_RADIUS
		var vect = (event.position - stick_pos).normalized()
		
		var ang = event.position.angle_to_point(stick_pos)
		
		$"../".stick_vector = vect
		$"../".stick_angle = ang
		$"../".stick_speed = dist
		
		$Small.position = vect * dist

and for the second analog :

extends Sprite

const RADIUS = 64
const SMALL_RADIUS = 32

var usage = false
var stick_pos
var evt_index = -1
var test

func _init():
	stick_pos = position

func _input(event):
	if event is InputEventScreenTouch:
		if event.is_pressed():
			if stick_pos.distance_to(event.position) < RADIUS:
				evt_index = event.index
				test = evt_index
		elif evt_index != -1:
			if evt_index == event.index:
				evt_index = -1
				$Small2.position = Vector2()
				$"../".stick_vector = Vector2()
				#$"../".stick_angle = 0
				$"../".stick_speed = 0
				usage = false
			
	if evt_index != -1 and event is InputEventScreenDrag:
		var dist = stick_pos.distance_to(event.position)
		if dist + SMALL_RADIUS >RADIUS:
			dist = RADIUS - SMALL_RADIUS
		var vect = (event.position - stick_pos).normalized()
		
		var ang = event.position.angle_to_point(stick_pos)
		
		$"../".stick_vector = vect
		$"../".stick_angle = ang
		$"../".stick_speed = dist
		
		usage = true
		
		$Small2.position = vect * dist

Did you use any particular nodes for the sticks?

DodoIta | 2018-07-05 07:44

Hello. Just canvas layer as a parents as UI for two srpites. One for place for analog(how much u can deflect analog) and second is smaller as an analog.

JokerDDZ | 2018-07-05 10:32