Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CustomOBBCollider coll = (CustomOBBCollider)collider;
- for (int i = 0; i < points.Length; i++)
- {
- Vector3 face = (new Vector2(transform.position.x, transform.position.y) + points[(i + 1) % points.Length]) -
- (new Vector2(transform.position.x, transform.position.y) + points[i]);
- Vector2 normal = Vector3.Cross(face, new Vector3(0, 0, 1)).normalized;
- projectedPointsOwn.Clear();
- projectedPointsColl.Clear();
- for (int j = 0; j < points.Length; j++)
- {
- projectedPointsOwn.Add(Project(normal, new Vector2(transform.position.x, transform.position.y) + points[j]));
- }
- for (int j = 0; j < coll.points.Length; j++)
- {
- projectedPointsColl.Add(Project(normal, new Vector2(coll.transform.position.x, coll.transform.position.y) + coll.points[j]));
- }
- minPoint = Vector2.positiveInfinity;
- maxPoint = Vector2.negativeInfinity;
- for (int j = 0; j < projectedPointsOwn.Count; j++)
- {
- if (projectedPointsOwn[j].x < minPoint.x)
- {
- minPoint.x = projectedPointsOwn[j].x;
- }
- if (projectedPointsOwn[j].y < minPoint.y)
- {
- minPoint.y = projectedPointsOwn[j].y;
- }
- if (projectedPointsOwn[j].x > maxPoint.x)
- {
- maxPoint.x = projectedPointsOwn[j].x;
- }
- if (projectedPointsOwn[j].y > maxPoint.y)
- {
- maxPoint.y = projectedPointsOwn[j].y;
- }
- }
- bool didOverlap = false;
- for (int j = 0; j < projectedPointsColl.Count; j++)
- {
- if (projectedPointsColl[j].x < maxPoint.x && projectedPointsColl[j].x > minPoint.x &&
- projectedPointsColl[j].y < maxPoint.y && projectedPointsColl[j].y > minPoint.y)
- {
- didOverlap = true;
- break;
- }
- }
- if (!didOverlap)
- {
- return false;
- }
- }
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement