Example #1
0
        public void UpdateSensorShape()
        {
            if (SensorShape != null)
            {
                Body.RemoveShape(SensorShape);
            }

            Rect largeRect = new Rect();

            foreach (var rect in Body.Shapes.Select(s => s.AABB))
            {
                largeRect = largeRect.ExpandedToContain(rect);
            }

            CircleShapeInfo circleShape = new CircleShapeInfo(
                (float)Math.Sqrt(Math.Pow(largeRect.W / 2, 2) + Math.Pow(largeRect.H / 2, 2) + Range),
                new Vector2(),
                0);

            circleShape.IsSensor = true;

            SensorShape = circleShape;

            Body.AddShape(circleShape);
        }