How can I make the vertices of a polygon in libgdx? I am trying to make a pentagon for collision detection and I am kind of confused about how the vertices part is done, until now I used rectangle to achieve this
How can I make the vertices of a polygon in libgdx? I am trying to make a pentagon for collision detection and I am kind of confused about how the vertices part is done, until now I used rectangle to achieve this
You should make several polygons since a pentagon is a convex shape and not easy to compute if a point is within the shape.
To create a shape with the Polygon class you specify the vertices with a float array. In sequence, you specify the x and y positions. Since Polygon is a 2D shape in Libgdx the Z axis is not needed.
Below is a polygon for a triangle shape, create your pentagon like this from multiple polygons and use Intersector to test the polygon vs various other geometry like lines and points. Note, Intersector does contain method overlapConvexPolygon but I am pretty sure that gives true for something in between the points of your pentagon.
new Polygon(new Array[
0, 0,
10, 0,
5, 10
]);