Beispiel #1
0
 public bool collidesWith(BreuAABB other)
 {
     //check for gap to the left
     if (other.Max.x < this.Min.x)
     {
         return(false);//no collision
     }
     //check for gap to the right
     if (other.Min.x > this.Max.x)
     {
         return(false);//no collision
     }
     //check for gap above
     if (other.Min.y > this.Max.y)
     {
         return(false);//no collision
     }
     //check for gap below
     if (other.Max.y < this.Min.y)
     {
         return(false);//no collision
     }
     //if no gaps are found, return true
     return(true);
 }
Beispiel #2
0
        /// <summary>
        /// this function returns how far to move THIS aabb
        /// so that it no longer overlaps another.
        /// assumed that the two overlap.
        /// only solves overlap in 2D, X-axis & Y-axis.
        /// </summary>
        /// <param name="other"></param>
        /// <returns>how far to move this object in meters</returns>
        public Vector3 findFix(BreuAABB other)
        {
            float moveRight = other.Max.x - this.Min.x;
            float moveLeft  = other.Min.x - this.Max.x;
            float moveUp    = other.Max.y - this.Min.y;
            float moveDowm  = other.Min.y - this.Max.y;

            Vector3 fix = new Vector3();

            fix.x = (Mathf.Abs(moveLeft) < Mathf.Abs(moveRight)) ? moveLeft : moveRight;
            fix.y = (Mathf.Abs(moveUp) < Mathf.Abs(moveDowm)) ? moveUp : moveDowm;
            if (Mathf.Abs(fix.x) < Mathf.Abs(fix.y))
            {
                fix.y = 0;
            }
            else
            {
                fix.x = 0;
            }

            return(fix);
        }