예제 #1
0
        /// <summary>
        /// Physically check for wall info between player and wall he's attached to.  Searches in front of player if no wall already set.
        /// </summary>
        private void GetClimbedWallInfo()
        {
            RaycastHit hit;

            Vector3 p1 = controller.transform.position + controller.center + Vector3.up * -controller.height * 0.40f;
            Vector3 p2 = p1 + Vector3.up * controller.height;

            // decide what direction to look towards to get the ledge direction vector
            Vector3 wallDirection;

            if (moveScanner.AboveBehindWall != null)
            {
                moveScanner.CutAndPasteAboveBehindWallTo(ref myLedgeDirection);
            }
            else if (moveScanner.BelowBehindWall != null)
            {
                moveScanner.CutAndPasteBelowBehindWallTo(ref myLedgeDirection);
            }

            if (myLedgeDirection == Vector3.zero)
            {
                wallDirection = controller.transform.forward;
            }
            else if (!atOutsideCorner)
            {
                wallDirection = myLedgeDirection;
            }
            else
            {
                wallDirection = -cornerNormalRay.direction;
            }
            // Cast character controller shape forward to see if it is about to hit anything.
            Debug.DrawRay(controller.transform.position, wallDirection, Color.gray);
            if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, 0.20f))
            {
                // Get the negative horizontal component of the hitnormal, so gabled roofs don't mess it up
                myLedgeDirection = Vector3.ProjectOnPlane(-hit.normal, Vector3.up).normalized;

                // set origin of strafe ray to y level of controller
                // direction is set to hitnormal until it can be adjusted when we have a side movement direction
                myStrafeRay = new Ray(new Vector3(hit.point.x, controller.transform.position.y, hit.point.z), hit.normal);
            }
            else
            {
                if (myLedgeDirection == Vector3.zero && moveScanner.FrontWall != null)
                {
                    moveScanner.CutAndPasteFrontWallTo(ref myLedgeDirection);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Physically check for wall info between player and wall he's attached to.  Searches in front of player if no wall already set.
        /// </summary>
        private void GetClimbedWallInfo()
        {
            RaycastHit hit;

            Vector3 p1 = controller.transform.position + controller.center + Vector3.up * -controller.height * 0.40f;
            Vector3 p2 = p1 + Vector3.up * controller.height;

            // decide what direction to look towards to get the ledge direction vector
            if (moveScanner.AboveBehindWall != null)
            {
                moveScanner.CutAndPasteAboveBehindWallTo(ref myLedgeDirection);
            }
            else if (moveScanner.BelowBehindWall != null)
            {
                moveScanner.CutAndPasteBelowBehindWallTo(ref myLedgeDirection);
            }

            if (myLedgeDirection == Vector3.zero)
            {
                wallDirection = controller.transform.forward;
            }
            else if (!atOutsideCorner)
            {
                wallDirection = myLedgeDirection;
            }
            else
            {
                wallDirection = -cornerNormalRay.direction;
            }
            // Cast character controller shape forward to see if it is about to hit anything.
            Debug.DrawRay(controller.transform.position, wallDirection, Color.gray);
            if (Physics.CapsuleCast(p1, p2, controller.radius, wallDirection, out hit, controller.radius + 0.1f))
            {
                // Immediately stop climbing if object not valid
                if (!IsClimable(hit.transform))
                {
                    StopClimbing();
                    return;
                }

                // Show climbing message then disable further showing of climbing mode message until current climb attempt is stopped
                if (showClimbingModeMessage)
                {
                    DaggerfallUI.AddHUDText(TextManager.Instance.GetLocalizedText("climbingMode"));
                    showClimbingModeMessage = false;
                }

                // Get the negative horizontal component of the hitnormal, so gabled roofs don't mess it up
                myLedgeDirection = Vector3.ProjectOnPlane(-hit.normal, Vector3.up).normalized;

                // set origin of strafe ray to y level of controller
                // direction is set to hitnormal until it can be adjusted when we have a side movement direction
                myStrafeRay = new Ray(new Vector3(hit.point.x, controller.transform.position.y, hit.point.z), hit.normal);
            }
            else
            {
                if (myLedgeDirection == Vector3.zero && moveScanner.FrontWall != null)
                {
                    moveScanner.CutAndPasteFrontWallTo(ref myLedgeDirection);
                }
            }
        }