Hello everyone, i’m trying to shape PolygonCollider2D in my game for detecting collision of the player, this picture is self-explanatory:
I have 3 waypoints, and in this 3 gameobjects i want to create a box for player trigger, but i can’t shape nicely the collider(documentations of unity is poor).
And this is the code:
PolygonCollider2D polygonCollider = GetComponent<PolygonCollider2D>(); //reference of polygonCollider
polygonCollider.points = new Vector2[waypoints.Count * 2]; //set double points for up and down from waypoint
Vector2[] tempPolygon = polygonCollider.points; //temp variable
int x = 0; // temp variable for get right waypoint(external array)
for (int i = 0; i < tempPolygon.Length - 1; i = i + 2)
{
//set point from waypoint to up
tempPolygon *= new Vector2(waypoints[x].localPosition.x, waypoints[x].localPosition.y + polygonHeight);*
//set point from waypoint to down
tempPolygon[i + 1] = new Vector2(waypoints[x].localPosition.x, waypoints[x].localPosition.y - polygonHeight);
//go to next waypoint
x++;
}
//update all points
polygonCollider.points = tempPolygon;
Thanks in advance! =)