Check if point intersects Area2D

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

How would you check if a point intersects an Area2D or a polygon? I’ve tried using DirectSpaceState, but it keeps returning null, so I need another solution.

:bust_in_silhouette: Reply From: estebanmolca

This can help you, in the godot doc:

Advance vector math

The CollisionShape2D class has a function (get_polygon ()) that returns the shape points in an array, which you can use to assemble the planes and apply the method explained in the documentation.
The Rect2 class also has a function (bool has_point (point: Vector2)) that returns true if it contains a given point, but of course, rect2 is a rectangle, but you could use more than one to get closer to the shape you want to check. That depends on the complexity of the form but it is an option to consider as well. I don’t know if there is any other way faster or easier.