Esempio n. 1
0
        void CornerAlign()
        {
            CornerAlignmentResult result = CornerAlignCollisions(
                characterController2D.Velocity.x > 0,
                cornerDetectionDistance,
                layerMask
                );

            if (result.success)
            {
                characterController2D.Teleport(result.point, result.normalRotation);
            }
        }
Esempio n. 2
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);
        }