// Check if polygon has ball objects inside public static bool PolygonHasBallsInside(Polygon2D poly) { foreach (ThinSliceBall ball in ThinSliceBall.GetList()) { if (poly.PointInPoly(new Vector2D(ball.transform.position)) == true) { return(true); } } return(false); }
public void BallToBallsCollision() { // Balls vs Balls Collision foreach (ThinSliceBall ball in ThinSliceBall.GetList()) { if (ball == this) { continue; } if (Vector2.Distance(transform.position, ball.transform.position) < ball.radius + radius) { ball.direction = Vector2D.RotToVec(Vector2D.Atan2(transform.position, ball.transform.position) - Mathf.PI).ToVector2(); direction = Vector2D.RotToVec(Vector2D.Atan2(transform.position, ball.transform.position)).ToVector2(); ball.transform.Translate(ball.direction * ball.speed); transform.Translate(direction * speed); } } }