Beispiel #1
0
        public override void handleCollision(Q3BSPLevel level, GameTime gameTime)
        {
            // if noclipping is enabled, do not check for collisions
            if (!m_settings.clipping)
            {
                position = newPosition;
            }
            // otherwise, check for collisions
            else
            {
                Q3BSPCollisionData collision = level.TraceBox(position, newPosition, minPoint, maxPoint);
                Vector3            point     = collision.collisionPoint;

                if (collision.collisionPoint != collision.endPosition)
                {
                    Vector3 start = collision.startPosition;
                    Vector3 col   = collision.collisionPoint;
                    Vector3 end   = collision.endPosition;

                    //Wall Detection: Not Working
                    //point = slopeCollision(level, start, col, end, m_left, 75);
                    //Ramp Detection
                    point = slopeCollision(level, start, col, end, new Vector3(0, 0.5f, 0), maxClimb);
                }
                position = point;

                //Gravity
                //Check if on floor
                collision = level.TraceBox(position, position - new Vector3(0, 1, 0), minPoint, maxPoint);
                if (collision.collisionPoint == collision.endPosition || isJumping)
                {
                    //Not on floor so check gravity
                    updateGravity(gameTime);
                    collision = level.TraceBox(position, newPosition, minPoint, maxPoint);
                    if (collision.collisionPoint != collision.endPosition)
                    {
                        resetGravity();
                    }
                    position = collision.collisionPoint;
                }
                else
                {
                    //On floor don't do gravity, but reset it
                    resetGravity();
                }
            }
        }
Beispiel #2
0
        public override void handleCollision(Q3BSPLevel level, GameTime gameTime)
        {
            if (!active)
            {
                return;
            }

            //Simple collision detection against level
            Q3BSPCollisionData collision = level.TraceBox(position, newPosition, minPoint, maxPoint);

            position = collision.collisionPoint;
        }
Beispiel #3
0
        private Vector3 slopeCollision(Q3BSPLevel level, Vector3 start, Vector3 collision, Vector3 end, Vector3 offset, float angle)
        {
            start += offset;
            end   += offset;

            // check the slope of a collision face
            Q3BSPCollisionData slopetest = level.TraceBox(start, end, minPoint, maxPoint);

            // get the angle of the collision face, and check to see that it is not too steep for the player to climb, then return the appropriate collision point
            if (slopetest.collisionPoint != collision + offset)
            {
                float opp   = offset.Length();
                float adj   = (end - start).Length();
                float theta = MathHelper.ToDegrees((float)Math.Atan(opp / adj));
                if (theta < angle)
                {
                    return(slopetest.collisionPoint);
                }
            }

            return(collision);
        }