Esempio n. 1
0
        /// <summary>
        /// Returns true if wall run can be intiated.
        /// Caches WallRunRaycastResult into a RaycastResult variable.
        /// </summary>
        /// <returns></returns>
        public bool TryToWallRun(CharacterControllerBase parent)
        {
            bool                 success             = false;
            Collider             lastWallRunCollider = null;
            WallRunRaycastResult result;

            if (RaycastResult != null)
            {
                lastWallRunCollider = RaycastResult.Hit.collider;
            }

            if (raycastWalls(parent.transform, raycastLength, out result, layerMask))
            {
                if (lastWallRunCollider == null ||
                    (lastWallRunCollider != RaycastResult.Hit.collider) ||
                    (lastWallRunCollider == RaycastResult.Hit.collider))
                {
                    success       = true;
                    RaycastResult = result;
                    Vector3 v   = parent.GetLookDirection();
                    Vector3 n   = RaycastResult.Hit.normal;
                    Vector3 vtn = Vector3.Cross(v, n);
                    Vector3 res = Vector3.Cross(n, vtn);
                    res.y = 0f;
                    RaycastResult.RunDirection = res;

                    Debug.DrawRay(RaycastResult.Hit.point, res * 10, Color.magenta, 1f);
                }
            }

            return(success);
        }
Esempio n. 2
0
        public bool ShouldStartWallRunState(CharacterControllerBase parent)
        {
            bool result = false;

            if (isInitializationTimerRunning && initializationTimer >= 0.2f)
            {
                if (TryToWallRun(parent))
                {
                    result = true;
                }
            }

            return(result);
        }