+1 vote

hey, so i'm making an asteroids clone and i'm stuck in this peculiar problem.

this is my node tree
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

node tree without nested viewport containers

btw i have "emulate touch from mouse" ticked in project settings

project settings

Godot version Godot_v3.4-stable_win64
in Engine by (62 points)

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

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

1 Answer

+1 vote
Best answer

Moving answer here :
"did You set containers MOUSE_FILTER to ignore ? All Control nodes have it blocking touch and mouse by default"

Thank You, glad I could help :)

by (7,447 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.