示例#1
0
        /// <summary>
        /// Detects collisions in the XY plane.
        /// </summary>
        /// <param name="performResponse">Whether to fix any collisions. Defaults to true.</param>
        /// <returns>A CollisionType indicating whether a collision happened.</returns>
        public virtual CollisionType DoXYCollisionDetection(bool performResponse = true)
        {
            if (this.CheckFlags(ActorFlags.NoInteraction))  // Don't do collision detection if NoInteraction is set.
            {
                return(CollisionType.None);
            }

            Vector3k deltaDist          = Vector3k.Zero;
            Actor    firstCollision     = null;
            bool     spcColRespStopMove = false;

            foreach (Actor act in Core.Ticker.Thinkers) // Iterate through all actors.
            {
                if (act == null || act == this)         // Skip if the actor is null or act refers to itself
                {
                    continue;
                }
                if (act.CheckFlags(ActorFlags.NoBlockmap) || act.CheckFlags(ActorFlags.NoInteraction))   // Skip the actor if it has NoBlockmap or NoInteraction
                {
                    continue;
                }

                Vector3k distXY = bCylinder.IntersectionDistXY(act.bCylinder);
                if (distXY.LengthSquared < FixedMath.Square(this.Radius + act.Radius))
                {
                    if (performResponse)
                    {
                        deltaDist += (((act.Radius + this.Radius) / distXY.Length) - Accum.One) * distXY;
                    }
                    if (firstCollision == null)
                    {
                        firstCollision = act;
                    }

                    if (SpecialCollisionResponseXY(performResponse, act, act == firstCollision))
                    {
                        spcColRespStopMove = true;
                    }
                }
            }

            if (performResponse)
            {
                bCylinder.Position += deltaDist;
            }

            if (spcColRespStopMove)
            {
                return(CollisionType.SpcColResp_StopMovement);
            }
            else if (firstCollision != null)
            {
                return(CollisionType.Collision);
            }
            else
            {
                return(CollisionType.None);
            }
        }
示例#2
0
 /// <summary>
 /// Checks for intersection with a bounding cylinder in the XY axes.
 /// </summary>
 /// <param name="b">The bounding cylinder to check for intersection with.</param>
 /// <returns>Returns a boolean indicating whether an intersection happened.</returns>
 public bool IntersectsXY(BoundingCylinder b)
 {
     return(FixedMath.Abs(IntersectionDistXY(b).LengthSquared) < FixedMath.Square(this.Radius + b.Radius));
 }