![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | tshrpl |
hey, so i’m making an asteroids clone and i’m stuck in this peculiar problem.
this is my node tree
and this is my input script
extends Node
var clockwise : bool
var anticlockwise : bool
var forward : bool
var backward : bool
var shoot : bool
var state = {}
func _input(event):
if event is InputEventScreenTouch:
if event.pressed: # Down.
state[event.index] = event.position
else: # Up.
state.erase(event.index)
get_tree().set_input_as_handled()
elif event is InputEventScreenDrag: # Movement.
state[event.index] = event.position
get_tree().set_input_as_handled()
func _process(delta):
# var screen_res = get_viewport().size
var screen_res = Vector2(1920, 1080)
backward = false
forward = false
shoot = false
clockwise = false
anticlockwise = false
for key in state:
var pos = state[key]
if pos.x > screen_res.x/2 and pos.y > screen_res.y/2:
backward = true
if pos.x > screen_res.x/2 and pos.y < screen_res.y/2:
forward = true
if pos.x < screen_res.x/2 and pos.y > screen_res.y/2:
shoot = true
if pos.x < screen_res.x/8 and pos.y < screen_res.y/2:
anticlockwise = true
if pos.x > screen_res.x/8 and pos.x < screen_res.x/4 and pos.y < screen_res.y/2:
clockwise = true
print(state)
the above code always prints {}
but when i remove the nested viewport containers, the input script works
btw i have “emulate touch from mouse” ticked in project settings
I know You are actually advanced in this, but just in case - did You set containers MOUSE_FILTER to ignore ? All Control nodes have it blocking touch and mouse by default
Inces | 2021-11-16 20:48
yes! setting Mouse/Filter to Ignore works, thank you so much, can you give an answer below so I can mark it as the correct answer
tshrpl | 2021-11-17 05:22