Example #1
0
        private static bool IsSpaceOffEdge(Collider2D col, BoxCollider2D playerCol)
        {
            bool isLeft = col.transform.gameObject.layer == _leftClimbLayer;

            RaycastHit2D[] hits = Physics2D.BoxCastAll((isLeft ? col.GetTopLeft() : col.GetTopRight()) + new Vector3(isLeft ? -playerCol.size.x / 2 : playerCol.size.x / 2, 0),
                                                       new Vector2(playerCol.size.x, 0.1f), 0, Vector2.up, playerCol.size.y, Layers.Platforms);

            return(ClimbCollision.IsCollisionInvalid(hits, col.transform) == false);
        }
Example #2
0
        public bool IsCollidingWithNonPivot(bool lowerHalf)
        {
            float  collisionFudge = 0.2f;
            Bounds bounds         = _motor.Collider.bounds;
            float  startY         = lowerHalf ? bounds.center.y : bounds.max.y;
            float  distance       = lowerHalf ? bounds.extents.y : bounds.size.y;

            RaycastHit2D[] hits = Physics2D.BoxCastAll(new Vector2(bounds.center.x, startY - collisionFudge), new Vector2(bounds.size.x - (collisionFudge * 2), 0.001f), 0, Vector2.down, distance - (collisionFudge * 2), Layers.Platforms);

            return(ClimbCollision.IsCollisionInvalid(hits, _motor.MovementState.Pivot.transform));
        }
Example #3
0
        private static bool IsEdgeUnblocked(Collider2D originalHit, Vector2 playerCentre, BoxCollider2D playerCol, bool above, bool allowExceptions = true)
        {
            Vector2 origin    = playerCentre;
            Vector2 target    = originalHit.bounds.center;
            Vector2 direction = target - origin;

            RaycastHit2D obstacleHit = Physics2D.Raycast(origin, direction, Vector2.Distance(target, origin), Layers.Platforms);

            Debug.DrawRay(origin, direction, Color.red);

            if (originalHit.transform.parent != obstacleHit.collider.transform && Vector2.Distance(obstacleHit.point, target) > 0.2f)
            {
                return(false);
            }

            float yOffset = above ? playerCol.size.y / 2 : -playerCol.size.y / 2;

            target    = originalHit.GetTopFace() + new Vector3(0, yOffset);
            direction = target - origin;
            float angle = above || originalHit.IsUpright() == false ? 0 : originalHit.transform.rotation.eulerAngles.z;

            RaycastHit2D[] obstacleHits = Physics2D.BoxCastAll(origin, new Vector2(0.01f, playerCol.size.y - 0.1f), angle, direction, Vector2.Distance(origin, target), Layers.Platforms);

            foreach (var hit in obstacleHits)
            {
                if (allowExceptions)
                {
                    if (originalHit.transform.parent == hit.collider.transform ||
                        Vector2.Distance(originalHit.transform.position, hit.point) < 1 ||
                        ClimbCollision.IsCollisionInvalid(new RaycastHit2D[] { hit }, originalHit.transform) == false)
                    {
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (originalHit.transform.parent == hit.collider.transform ||
                         Vector2.Distance(originalHit.transform.position, hit.point) < 1)
                {
                    continue;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }