Check if a Vector2 is inside Area2D

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

Supose I have a gesture detector node which returns the position when someone tap the screen (in case of mobile game), how can I check if this position is inside an Area2D? The signals body_enter and input_event won’t work for me in this case, I guess.

:bust_in_silhouette: Reply From: quijipixel

There is probably a better way to do this, but the first thing that popped into my mind was to create a collision body or area2d node without sprite, and move it to the vector position in order to trigger the Area2d event.

I was thinking the same thing right after I posted this. Do you know a better way to check without a Area2D?

CesarAugusto | 2017-08-30 01:11

Researching the Area2D found that you could get the collision shape by calling get_shape. This returns a Shape object that has the method collide. This method gets the local transform, another shape to test against and this shapes transform. You can check it on the docs. Its probably no the best solution, but it’s a step forward and a more elegant solution than the previous one.

quijipixel | 2017-08-30 02:26

:bust_in_silhouette: Reply From: eons

Physics2DDirectSpaceState.intersect_point may be what you want.

Just get the state from the world and do the queries.