Can anyone please tell that how will I check if a point is in a Polygon2D or not

in my case the Polygon is a rhombus with one diagonal 128 and other 64. The longer diagonal is horizontal and smaller diagonal is vertical

Godot version v3.2.3-stable_win64
in Engine

Hi...A technique is explained in the godot manual:

Godot has a class called Geometry and one of its methods is just what you are looking for:
https://docs.godotengine.org/en/stable/classes/class_geometry.html?highlight=geometry#class-geometry-method-is-point-in-polygon

In godot it would be used like this, passing it an array with the points of the polygon:

``````var polygon = [Vector2(0,0), Vector2(1,0), Vector2(1,1), Vector2(0,1)]
print(Geometry.is_point_in_polygon(Vector2(0.5,0.5),polygon)) #print true
print(Geometry.is_point_in_polygon(Vector2(2.5,0.5),polygon)) #print false
``````
by (2,260 points)
selected

I forgot, to know the points of the polygon use the polygon property of Polygon2D:
https://docs.godotengine.org/en/stable/classes/class_polygon2d.html#class-polygon2d-property-polygon

Thanks!
But I have doubt in second parameter of this method `is_point_in_polygon`
Can it be `\$Polygon2D.get_polygon()`?

Yes... If you can't make it work, tell me and I'll prepare an example

Thanks a lot!
You did a great help to me. I was earlier going to do very stupid things to make this work.
But now

``````func _input(event):
if event.is_action_pressed("click"):
if Geometry.is_point_in_polygon(event.position, \$Polygon2D.get_polygon()):
print("successs") ### And it prints success
``````

Very good. I'm glad I was helpful. The Geometry class has other useful functions like doing Boolean operations between polygons, intersections etc.