Exemple #1
0
        /// <summary>
        /// Determines if there are any gaps between one AABB and another.
        /// Only accounts for x and y axis.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool CollidesWith(PetzakAABB other)
        {
            // LightPlatform collision against player
            if (other.name.StartsWith("Light") && !this.name.StartsWith("Life"))
            {
                Recalc(); // make sure both objects have the correct min/max
                other.Recalc();
                PetzakPlayerMovement p     = this.GetComponentInParent <PetzakPlayerMovement>();
                bool closeEnough           = Math.Abs(other.max.y - this.min.y) < .2; // objects are very close to one another
                bool withinHorizontalRange = other.min.x <= this.max.x && other.max.x >= this.min.x;
                bool isNotMovingUp         = p.velocity.y <= 0;
                return(closeEnough && withinHorizontalRange && isNotMovingUp && !p.isJumping && !p.isGrounded);
            }

            if (other.max.x < this.min.x || // check for gap to left
                other.min.x > this.max.x || // check for gap to right
                other.min.y > this.max.y || // check for gap above
                other.max.y < this.min.y) // check for gap below
            {
                return(false);
            }

            return(true); // no gaps found
        }
 /// <summary>
 /// Instantiates _cam, mover, and pill objects on startup.
 /// </summary>
 void Awake()
 {
     _cam  = GetComponent <Camera>();
     mover = _player.GetComponent <PetzakPlayerMovement>();
     pill  = lifePill.GetComponentInParent <PetzakLifePill>();
 }