protected abstract bool DetectCollision(LineBody lineBody);
/// <summary> /// Detect collision with a line body /// </summary> /// <param name="lineBody"></param> /// <returns></returns> protected override bool DetectCollision(LineBody lineBody) { return false; }
/// <summary> /// Detect a collision with a line body /// </summary> /// <param name="lineBody"></param> /// <returns></returns> protected override bool DetectCollision(LineBody lineBody) { Vector2 closestPointOnLineBody = lineBody.GetClosestPointOnPerimeter(this.Position); bool touchingLine = ((closestPointOnLineBody - this.Position).LengthSquared() < this.Radius * this.Radius); bool willCrossLine = !(this.Position - closestPointOnLineBody).HasSameDirection(this.Position - this.Velocity - lineBody.GetClosestPointOnPerimeter(this.Position - this.Velocity)); bool result = touchingLine || willCrossLine; return result; }