Exemplo n.º 1
0
 public static void DrawRect(OrientedRect rect, Color color, float duration = 0, float y = 0)
 {
     Debug.DrawLine(rect.LowerLeft.ToXZ(y), rect.LowerRight.ToXZ(y), color, duration);
     Debug.DrawLine(rect.LowerRight.ToXZ(y), rect.UpperRight.ToXZ(y), color, duration);
     Debug.DrawLine(rect.UpperRight.ToXZ(y), rect.UpperLeft.ToXZ(y), color, duration);
     Debug.DrawLine(rect.UpperLeft.ToXZ(y), rect.LowerLeft.ToXZ(y), color, duration);
 }
        public void Update()
        {
            var center   = Center.transform.position.TakeXZ();
            var dir      = (End.position - Center.position).normalized.TakeXZ();
            var dist     = (End.position - Center.position).magnitude;
            var obstacle = new Rect(ObstacleStart.position.TakeXZ(), (ObstacleEnd.position - ObstacleStart.position).TakeXZ());

            var rect = new OrientedRect(center, dir, dist, Width);


            var hit = Collision2DHelper.Intersects(obstacle, rect);



            DrawHelpers.DrawRect(rect, hit ? Color.red : Color.green);

            DrawHelpers.DrawRect(obstacle, Color.blue);
            DrawHelpers.DrawRect(rect.GetAABB(), Color.black);
        }