Beispiel #1
0
        /// <summary>
        /// Check if the wall slide ability conditions are met (a wall in front of the character with the corresponding "Wall Sliding" Tag).
        /// </summary>
        public bool CheckWallSliding()
        {
            if (characterController2D.IsGrounded)
            {
                return(false);
            }

            if (characterBrain.CharacterAction.down)
            {
                return(false);
            }

            if (characterController2D.Velocity.y > 0)
            {
                return(false);
            }

            CollisionHitInfo info = new CollisionHitInfo();

            info.Reset();

            CardinalCollisionType cardinalCollisionType =
                characterController2D.IsFacingRight ?
                CardinalCollisionType.Right :
                CardinalCollisionType.Left;

            float skin = characterBody.SkinWidth;

            info = characterController2D.CharacterCollisions.CardinalCollision(
                cardinalCollisionType,
                skin,
                skin,
                layerMask
                );

            if (!info.collision)
            {
                return(false);
            }

            float wallSignedAngle = Utilities.SignedAngle(characterBody.bodyTransform.Up, info.normal, characterBody.bodyTransform.Forward);
            float wallAngle       = Mathf.Abs(wallSignedAngle);

            if (!info.gameObject.CompareTag(wallSlideTag) || !Utilities.isCloseTo(wallAngle, 90, 0.1f))
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public override void Process(float dt)
        {
            if (!movementController.isCurrentlyOnState(MovementState.Normal))
            {
                return;
            }

            if (!characterController2D.IsGrounded)
            {
                return;
            }

            hitInfo.Reset();

            CardinalCollisionType cardinalCollisionType =
                characterController2D.IsFacingRight ?
                CardinalCollisionType.Right :
                CardinalCollisionType.Left;


            float skin = characterBody.SkinWidth;

            hitInfo = characterController2D.CharacterCollisions.CardinalCollision(
                cardinalCollisionType,
                skin,
                skin,
                wallLayerMask
                );

            if (hitInfo.collision)
            {
                float wallSignedAngle = Utilities.SignedAngle(characterController2D.transform.up, hitInfo.normal, characterController2D.transform.forward);
                float wallAngle       = Mathf.Abs(wallSignedAngle);

                if (Utilities.isCloseTo(wallAngle, 90f, 0.1f))
                {
                    characterController2D.Teleport(hitInfo.point, Quaternion.LookRotation(Vector3.forward, hitInfo.normal));

                    if (OnWallAlignmentPerformed != null)
                    {
                        OnWallAlignmentPerformed();
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Performs the collision detection method used in the "Corner Alignment" feature.
        /// </summary>
        CornerAlignmentResult CornerAlignCollisions(bool positiveDirection, float cornerDetectionDistance, LayerMask layerMask)
        {
            CornerAlignmentResult result = new CornerAlignmentResult();

            result.Reset();

            CollisionHitInfo hitInfo = new CollisionHitInfo();

            hitInfo.Reset();

            if (cornerDetectionDistance < 0)
            {
                return(result);
            }

            float castDistance = characterBody.SkinWidth + cornerDetectionDistance;


            Vector2 rayOrigin = characterController2D.transform.position +
                                (positiveDirection ? -1 : 1) * characterController2D.transform.right * characterBody.verticalArea / 2 -
                                characterController2D.transform.up * characterBody.SkinWidth;

            hitInfo = PhysicsUtilities.Raycast(
                characterBody.Is3D(),
                rayOrigin,
                (positiveDirection ? -1 : 1) * characterController2D.transform.right,
                castDistance,
                layerMask
                );

            if (hitInfo.collision)
            {
                result.point          = hitInfo.point;
                result.normalRotation = Quaternion.LookRotation(characterBody.bodyTransform.Forward, hitInfo.normal);
                result.success        = true;
            }



            return(result);
        }