/// <summary> /// 将trigger位置摆到body位置前面 /// </summary> /// <param name="body"></param> /// <param name="trigger"></param> /// <param name="distance"></param> /// <param name="dectectionLayer"></param> public static void Detection(this Body body, Body trigger, double distance, DectectionLayer dectectionLayer = DectectionLayer.All) { if (trigger == null) { return; } trigger.Position.Set(body.Position); trigger.InitAngle(body.Angle); trigger.Velocity = body.Velocity + body.Forward * 10; trigger.AngularVelocity = 0; }
/// <summary> /// 触发检测 /// </summary> /// <param name="body"></param> /// <param name="trigger"></param> /// <param name="distance"></param> public static void TriggerDetection(this Body body, Body trigger, double distance, DectectionLayer dectectionLayer = DectectionLayer.All) { if (!trigger.Trigger) { return; } trigger.Position = body.Position + body.Forward * distance; trigger.InitAngle(body.Angle); }
/// <summary> /// 环形检测 /// </summary> /// <param name="body"></param> /// <param name="bodies">被检测的物体组</param> /// <param name="radius">检测的半径</param> /// <param name="layer">检测的层</param> /// <returns>检测到的物体,按照距离进行排序</returns> public static List <Body> RingDetection(this Body body, IEnumerable <Body> bodies, double radius, DectectionLayer layer = DectectionLayer.All) { List <tempBody> CollisionalBodies = new List <tempBody>(); foreach (var b in bodies) { var distanceNoSqrt = Helper.DistanceNoSqrt(body.Position, b.Position); if (distanceNoSqrt < radius * radius) { CollisionalBodies.Add(new tempBody(b, Math.Sqrt(distanceNoSqrt))); } } return((from o in CollisionalBodies.OrderBy(o => o.Distance) select o.Body).ToList()); }