what is under my finger? ( touch screen )

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By baribal
:warning: Old Version Published before Godot 3 was released.


i would like to get objects under my finger on touch screen, Not only on press on that objects, but when i move finger and get collision with them. Is any way to do that nicely ?

For now, what i’m thinking about is dragging hidden object to x,y of touch, and collide it with the objects under

:bust_in_silhouette: Reply From: fredspipa

Hey baribal!

I’d have an Area2D node that get its position updated with the InputEvent.SCREEN_DRAG, on which I’d subscribe to the body_enter or area_enter signals. You could do set_enable_monitoring on the Area2D node when InputEvent.SCREEN_TOUCH is fired, using the event.pressed boolean as an argument.

Here’s an example:

func _input(event):
    if event.type == InputEvent.SCREEN_TOUCH:
    elif event.type == InputEvent.SCREEN_DRAG:

You might need to point out to add the set_process_input(true) in the area 2d _ready function too

RobertBrooks | 2017-04-04 22:11

:bust_in_silhouette: Reply From: Zylann

You can detect mouse and touch input on Area2D or other physics nodes (as you would on Controls) if you enable the pickable property. If you do so, you will get regular input events from them by connecting the input_event to your custom function CollisionObject2D — Godot Engine (stable) documentation in English

Hi there, jumping in on this thread as I’m trying the same thing.

I made an Area2D pick-able.
I then connected the input_event signal to my own function as so:

func _on_Area2DL_input_event( viewport, event, shape_idx ):
	print("viewport: ", viewport)
	print("event: ", event)
	print("shape_idx: ", shape_idx)

I have emulate_touchscreen turned on and when I click on the Area2D none of the print statements show anything (as in they don’t trigger at all).

I’m guessing I’m misunderstanding this? Can you or anyone explain what I’m doing wrong?

Thank you.

EDIT: I added a collision shape (rectangle) as a child of the Area2D and it worked. I don’t fully understand that but I’ll have a think and a read to make sense of it all.

Robster | 2017-02-20 05:01