Example #1
0
        /// <summary>
        /// Calls the appropriate check function against the type of the inputted collider.
        /// </summary>
        /// <param name="collider">The collider to check against</param>
        /// <returns>Returns true if a collision occurred</returns>
        public virtual bool CheckCollisionWith(Collider collider)
        {
            RectangleCollider rectangleCollider = collider as RectangleCollider;

            if (rectangleCollider != null)
            {
                bool result = CheckCollisionWith(rectangleCollider);
                CollidedThisFrame = CollidedThisFrame || result;

                return(result);
            }

            CircleCollider circleCollider = collider as CircleCollider;

            if (circleCollider != null)
            {
                bool result = CheckCollisionWith(rectangleCollider);
                CollidedThisFrame = CollidedThisFrame || result;

                return(result);
            }

            DebugUtils.Fail("Checking against an unknown collider.");
            return(false);
        }
 protected override bool CheckCollisionWith(CircleCollider circleCollider)
 {
     return((circleCollider.Parent.WorldPosition - Parent.WorldPosition).LengthSquared() <= (circleCollider.Radius * circleCollider.Radius + Radius * Radius));
 }
Example #3
0
 /// <summary>
 /// Check collision with inputted circle collider and updates the CollidedThisFrame bool
 /// </summary>
 /// <param name="circleCollider">The circle collider to check against</param>
 /// <returns>True if a collision occurred</returns>
 protected abstract bool CheckCollisionWith(CircleCollider circleCollider);
 protected override bool CheckCollisionWith(CircleCollider circleCollider)
 {
     throw new NotImplementedException();
 }