public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateUpdate(animator, stateInfo, layerIndex); if (Input.GetKeyDown(KeyCode.K)) { if (stateInfo.IsName("PowerAttack.powerattack_1") && stateInfo.normalizedTime > 0.35f) { animator.CrossFade("powerattack_2", 0); } else if (stateInfo.IsName("PowerAttack.powerattack_2") && stateInfo.normalizedTime > 0.35f) { animator.CrossFade("powerattack_3", 0); } else if (stateInfo.IsName("PowerAttack.powerattack_3") && stateInfo.normalizedTime > 0.35f) { animator.CrossFade("powerattack_4", 0); } else if (stateInfo.IsName("PowerAttack.powerattack_4") && stateInfo.normalizedTime > 0.35f) { animator.CrossFade("powerattack_5", 0); } } }
void Awake(){ audio = this.gameObject.AddComponent<AudioSource>(); audio.playOnAwake = false; audio.loop = false; my_transform = this.gameObject.GetComponent<Transform> (); move_enemy = my_transform.Find ("ob"); if(move_enemy == null){ Debug.Log("move_enemy is null"); } player = move_enemy.Find("fast_move_enemy").gameObject.GetComponent<Animator>(); up_check = my_transform.Find ("up_check"); down_check = my_transform.Find ("down_check"); left_check = my_transform.Find ("left_check"); right_check = my_transform.Find ("right_check"); if (stand_direction == 1) { player.CrossFade ("stand", 0); } else if (stand_direction == 2) { player.CrossFade ("down",0); }else if (stand_direction == 3) { player.CrossFade ("left_stand",0); }else if (stand_direction == 4) { player.CrossFade ("right_stand",0); } }
void Awake(){ audio = this.gameObject.AddComponent<AudioSource>(); audio.playOnAwake = false; audio.loop = false; my_transform = this.gameObject.GetComponent<Transform> (); move_enemy = my_transform.Find ("ob"); player = move_enemy.Find("attact_enemy").gameObject.GetComponent<Animator>(); bar = this.gameObject.transform.Find("barrel").GetComponent<BoxCollider2D>(); if (stand_direction == 1) { player.CrossFade ("stand_", 0); } else if (stand_direction == 2) { player.CrossFade ("down",0); }else if (stand_direction == 3) { player.CrossFade ("left_stand",0); }else if (stand_direction == 4) { player.CrossFade ("right_stand",0); } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //} // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //} // OnStateExit is called when a transition ends and the state machine finishes evaluating this state public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { var currentDirection = (Direction)animator.GetInteger("FaceDirection"); if (animator.GetBool("MeleeAttackBool")) { animator.SetBool("MeleeAttackBool", false); switch (currentDirection) { case Direction.Up: animator.CrossFade("P_Idle_Up", 0.5f); break; case Direction.Down: animator.CrossFade("P_Idle_Down", 0.5f); break; case Direction.Left: animator.CrossFade("P_Idle_Left", 0.5f); break; case Direction.Right: animator.CrossFade("P_Idle_Right", 0.5f); break; } } ResetAnimationState(animator); }
void Awake(){ audio = this.gameObject.AddComponent<AudioSource>(); audio.playOnAwake = false; audio.loop = false; my_transform = this.gameObject.GetComponent<Transform> (); normal_enymy = my_transform.Find ("normal_enymy"); player = my_transform.Find ("normal_enymy").gameObject.GetComponent<Animator> (); up_check = my_transform.Find ("up_check"); down_check = my_transform.Find ("down_check"); left_check = my_transform.Find ("left_check"); right_check = my_transform.Find ("right_check"); if (stand_direction == 1) { player.CrossFade ("stand_", 0); } else if (stand_direction == 2) { player.CrossFade ("down",0); }else if (stand_direction == 3) { player.CrossFade ("left_stand",0); }else if (stand_direction == 4) { player.CrossFade ("right_stand",0); } compress (); }
void Awake(){ audio = this.gameObject.AddComponent<AudioSource>(); AudioClip clip = Resources.Load<AudioClip>("sound/trap"); audio.playOnAwake = false; audio.loop = false; audio.clip = clip; change_times = g_d_m.chang_number; player = this.gameObject.GetComponent<Animator> (); if (direction == 1) { player.CrossFade ("left_idle",0f); } else { player.CrossFade ("right_idle",0f); } }
public void ResetAnimationState(Animator animator) { var currentDirection = (Direction)animator.GetInteger("FaceDirection"); switch (currentDirection) { case Direction.Up: animator.CrossFade("P_Idle_Up", 0.5f); break; case Direction.Down: animator.CrossFade("P_Idle_Down", 0.5f); break; case Direction.Left: animator.CrossFade("P_Idle_Left", 0.5f); break; case Direction.Right: animator.CrossFade("P_Idle_Right", 0.5f); break; } }
// Use this for initialization void Start() { controle = GetComponent<CharacterController> (); alturaAtual = transform.position.y; alturaDoDano = alturaAtual; posicaoInicial = transform.position; transform.rotation = Quaternion.LookRotation (-direcaoDoDano); cancelaAcao(); animator = GetComponent<Animator>(); if(vivo) animator.CrossFade("dano1",0); }
void Start () { AI.GetComponent<EnemyController> ().enemyState = EnemyController.EnemyState.Walking; anim = GetComponent<Animator> (); anim.CrossFade ("Walking", 0.1f); alreadyRoom = new List<string> (); isChangingRoom = false; alreadyChangeRoom = false; isFromRoomToHall = false; //<Viên> Direction = 1; //<Lâm> //StartCoroutine (whatWayToGo (0.2f)); }
void FixedUpdate() { //increase the noCollisionTimer (if there is a collision, the noCollisionTimer is later set to 0) noCollisionTimer++; //setting the scale of the rays to the scale of the script holder if (inheritScale) { height2 = transform.localScale.y; width2 = transform.localScale.x; length2 = transform.localScale.z; } //storing values to variables onLedgeHeight2 = onLedgeHeight + 0.06f; height2 = overallScaleOfDetectors.height; length2 = overallScaleOfDetectors.length * 0.77f; width2 = overallScaleOfDetectors.width * 0.77f; posChange1 = transform.up * overallPositionOfDetectors.upDistance + transform.forward * overallPositionOfDetectors.forwardDistance + transform.right * overallPositionOfDetectors.sideDistance; posChange2 = (transform.up * overallPositionOfDetectors.upDistance - transform.up * onLedgeHeight2 / 10) + transform.forward * overallPositionOfDetectors.forwardDistance + transform.right * overallPositionOfDetectors.sideDistance; midSidePosChange = heightOfMidSideDetectors2 * (height2 + (height2 - 1f) * 0.25f); upHeight = transform.up * height2; forwardLength = transform.forward * length2; rightWidth = transform.right * width2; ledgeSwitchHeight = (upHeight * (wallInFrontDetectorHeight2 + 1)); ledgeSwitchSurfaceLength = (forwardLength * (surfaceDetectorLength2 + 1)); ledgeSwitchFirstNoSurfaceLength = (forwardLength * (surfaceDetectorLength2 + firstNoSurfaceDetectorLength2 + 1)); ledgeSwitchSecondNoSurfaceLength = (forwardLength * (surfaceDetectorLength2 + secondNoSurfaceDetectorLength2 + 1)); ledgeSwitchThirdNoSurfaceLength = (forwardLength * (surfaceDetectorLength2 + thirdNoSurfaceDetectorLength2 + 1)); ledgeSwitchFirstWidthBack = ((rightWidth * 2.67f + firstSwitchSurfaceWidth - surfaceDetectorForward2) * ((noSurfaceDetectorWidth2 + firstNoSurfaceDetectorWidth2) + 1)) / (2 + (noSurfaceDetectorWidth2 + firstNoSurfaceDetectorWidth2)); ledgeSwitchFirstWidthForward = ((rightWidth * 2.67f + firstSwitchSurfaceWidth + surfaceDetectorForward2) * ((noSurfaceDetectorWidth2 + firstNoSurfaceDetectorWidth2) + 1)) / (2 + (noSurfaceDetectorWidth2 + firstNoSurfaceDetectorWidth2)); ledgeSwitchSecondWidthForward = ((rightWidth * 2.67f + secondSwitchSurfaceWidth + surfaceDetectorForward2) * ((noSurfaceDetectorWidth2 + secondNoSurfaceDetectorWidth2) + 1)) / (2 + (noSurfaceDetectorWidth2 + secondNoSurfaceDetectorWidth2)); ledgeSwitchSecondWidthBack = ((rightWidth * 2.67f + secondSwitchSurfaceWidth - surfaceDetectorForward2) * ((noSurfaceDetectorWidth2 + secondNoSurfaceDetectorWidth2) + 1)) / (2 + (noSurfaceDetectorWidth2 + secondNoSurfaceDetectorWidth2)); ledgeSwitchThirdWidthForward = ((rightWidth * 2.67f + thirdSwitchSurfaceWidth + surfaceDetectorForward2) * ((noSurfaceDetectorWidth2 + thirdNoSurfaceDetectorWidth2) + 1)) / (2 + (noSurfaceDetectorWidth2 + thirdNoSurfaceDetectorWidth2)); ledgeSwitchThirdWidthBack = ((rightWidth * 2.67f + thirdSwitchSurfaceWidth - surfaceDetectorForward2) * ((noSurfaceDetectorWidth2 + thirdNoSurfaceDetectorWidth2) + 1)) / (2 + (noSurfaceDetectorWidth2 + thirdNoSurfaceDetectorWidth2)); jumpLandingEffect2 = walkingOffLedgeDetectors.jumpLandingEffect; hit = new RaycastHit(); //updating the current state variables if ((climbable || climbPossible) && !Physics.Linecast(transform.position + posChange1 + upHeight, new Vector3(transform.position.x, (playerPosY + onLedgeHeight2 / 10), transform.position.z) + posChange1 - upHeight / 3f + minDistFromGroundHeight2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, new Vector3(transform.position.x, (playerPosY + onLedgeHeight2 / 10), transform.position.z) + posChange1 - upHeight / 3f + minDistFromGroundHeight2 - (rightWidth / 4) - minDistFromGroundWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, new Vector3(transform.position.x, (playerPosY + onLedgeHeight2 / 10), transform.position.z) + posChange1 - upHeight / 3f + minDistFromGroundHeight2 + (rightWidth / 4) + minDistFromGroundWidth2, out hit, collisionLayers) || grabbedOn) { currentStatesOfVariables.ledgeGrabPossible = true; } else { currentStatesOfVariables.ledgeGrabPossible = false; } if (climbable && climbableL && climbableR && !Physics.Linecast(transform.position + posChange2 + upHeight, transform.position + posChange2 + upHeight * 2.5f + spaceAboveHeadNeededToClimbUp2, out hit, collisionLayers)) { currentStatesOfVariables.climbUpPossible = true; } else { currentStatesOfVariables.climbUpPossible = false; } if (!left || !leftMovable) { if (angledLeft || leftBlocked || sL || stuckToLeft) { currentStatesOfVariables.leftMovementPossible = false; } else { currentStatesOfVariables.leftMovementPossible = true; } } else { currentStatesOfVariables.leftMovementPossible = true; } if (!right || !rightMovable) { if (angledRight || rightBlocked || sR || stuckToRight) { currentStatesOfVariables.rightMovementPossible = false; } else { currentStatesOfVariables.rightMovementPossible = true; } } else { currentStatesOfVariables.rightMovementPossible = true; } currentStatesOfVariables.currentlyOnLedge = grabbedOn; //getting angle of ledge if (Physics.Raycast(transform.position + midSidePosChange + midSidePosChange + posChange2 + upHeight * 2.5f + forwardLength / 1.75f, -upHeight * 0.9f, out hit, 5f, collisionLayers)) { angle = (Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f; } else { angle = 90; } //checking if climbing is possible on surface height if (Physics.Linecast(transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.75f + underPlatformMaxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 - forwardLength / 20, transform.position + posChange2 - forwardLength / 20 + upHeight * 1.5f + spaceAboveHeadNeededToGrabOn2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 2.2f + maxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + underPlatformMaxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.7f + underPlatformMaxSurfaceLevelHeight2, out hit, collisionLayers)) { if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= 89 || ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 91) { if (angle <= ledgeAngleLimit) { climbPossible = true; playerPosY = hit.point.y - (height2 * 1.25f); if (grabbedOn && (playerPosY + onLedgeHeight2 / 10) != 0f) { transform.position = new Vector3(transform.position.x, (playerPosY + onLedgeHeight2 / 10), transform.position.z); } } } else { climbPossible = false; } } else if (Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.7f + underPlatformMaxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.7f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 - forwardLength / 20, transform.position + posChange2 - forwardLength / 20 + upHeight * 1.5f + spaceAboveHeadNeededToGrabOn2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + underPlatformMaxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.7f + underPlatformMaxSurfaceLevelHeight2, out hit, collisionLayers)) { if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= 89 || ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 91) { if (angle <= ledgeAngleLimit) { climbPossible = true; playerPosY = hit.point.y - (height2 * 1.25f); if (grabbedOn && (playerPosY + onLedgeHeight2 / 10) != 0f) { transform.position = new Vector3(transform.position.x, (playerPosY + onLedgeHeight2 / 10), transform.position.z); } } } else { climbPossible = false; } } else { climbPossible = false; if (!grabbedOn && !pullingUp && !turnBack && !back2) { if (Physics.Linecast(transform.position + posChange2 + upHeight / 2 + forwardLength / 1.52f + upHeight * 0.9f + (ledgeDetectorHeight2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f)) + (ledgeDetectorForward2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f))) + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2 + transform.forward * (topOfLedgeSurfaceDetectorHeight2 * length2) * 0.14f + transform.up * (topOfLedgeSurfaceDetectorHeight2 * height2)), transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f + (ledgeDetectorHeight2 + ledgeDetectorForward2 + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2), out hit, collisionLayers) && angle <= ledgeAngleLimit) { playerPosY = hit.point.y - (height2 * 1.25f); } else { playerPosY = transform.position.y - 1 * height2; } } } //checking if climbing is possible to the left if (Physics.Linecast(transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2 - rightWidth / 10, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f - rightWidth / 10, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.75f + underPlatformMaxSurfaceLevelHeight2 - rightWidth / 10, transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2 - rightWidth / 10, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 - forwardLength / 20 - rightWidth / 10, transform.position + posChange2 - forwardLength / 20 + upHeight * 1.5f + spaceAboveHeadNeededToGrabOn2 - rightWidth / 10, out hit, collisionLayers)) { if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= 89 || ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 91) { climbPossibleL = true; } } else if (Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.7f + underPlatformMaxSurfaceLevelHeight2 - rightWidth / 10, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.7f - rightWidth / 10, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 - forwardLength / 20 - rightWidth / 10, transform.position + posChange2 - forwardLength / 20 + upHeight * 1.5f + spaceAboveHeadNeededToGrabOn2 - rightWidth / 10, out hit, collisionLayers)) { if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= 89 || ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 91) { climbPossibleL = true; } } else { climbPossibleL = false; } //checking if climbing is possible to the left if (Physics.Linecast(transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2 + rightWidth / 10, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f + rightWidth / 10, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.75f + underPlatformMaxSurfaceLevelHeight2 + rightWidth / 10, transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2 + rightWidth / 10, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 - forwardLength / 20 + rightWidth / 10, transform.position + posChange2 - forwardLength / 20 + upHeight * 1.5f + spaceAboveHeadNeededToGrabOn2 + rightWidth / 10, out hit, collisionLayers)) { if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= 89 || ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 91) { climbPossibleR = true; } } else if (Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.7f + underPlatformMaxSurfaceLevelHeight2 + rightWidth / 10, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.7f + rightWidth / 10, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 - forwardLength / 20 + rightWidth / 10, transform.position + posChange2 - forwardLength / 20 + upHeight * 1.5f + spaceAboveHeadNeededToGrabOn2 + rightWidth / 10, out hit, collisionLayers)) { if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= 89 || ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 91) { climbPossibleR = true; } } else { climbPossibleR = false; } //left non-climbable detectors if (Physics.Linecast(transform.position + posChange2 + upHeight - rightWidth / 10, transform.position + posChange2 + (upHeight * 2) + forwardLength / 1.7f - (rightWidth / 4) + midSideWallDetectorsForward2 - midSideWallDetectorsWidth2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange2 + upHeight - rightWidth / 10, transform.position + posChange2 + (upHeight * 2) - rightWidth - sideWallDetectorsWidth2, out hit, collisionLayers)) { if (Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f - (rightWidth / 4) + frontSideBlockageDetectorsHeight2 - frontSideBlockageDetectorsWidth2, transform.position + posChange2 + upHeight * 1.5f + forwardLength * 1.2f - (rightWidth / 4) + frontSideBlockageDetectorsForward2 + frontSideBlockageDetectorsHeight2 - frontSideBlockageDetectorsWidth2, out hit, collisionLayers) || !Physics.Raycast(transform.position + midSidePosChange + midSidePosChange + posChange2 + upHeight * 1.5f + forwardLength / 1.6f - (rightWidth / 4), upHeight, out hit, 2f, collisionLayers) || !Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.6f - (rightWidth / 4) + frontSideBlockageDetectorsHeight2 - frontSideBlockageDetectorsWidth2 + aboveHeadPlatformDetectorsForward2, transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.25f - (rightWidth / 4) + frontSideBlockageDetectorsHeight2 - frontSideBlockageDetectorsWidth2 + aboveHeadPlatformDetectorsForward2 + aboveHeadPlatformDetectorsHeight2, out hit, collisionLayers)) { leftMovable = false; } else { leftMovable = true; } } else { leftMovable = true; } //right non-climbable detectors if (Physics.Linecast(transform.position + posChange2 + upHeight + rightWidth / 10, transform.position + posChange2 + (upHeight * 2) + forwardLength / 1.7f + (rightWidth / 4) + midSideWallDetectorsForward2 + midSideWallDetectorsWidth2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange2 + upHeight + rightWidth / 10, transform.position + posChange2 + (upHeight * 2) + rightWidth + sideWallDetectorsWidth2, out hit, collisionLayers)) { if (Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + (rightWidth / 4) + frontSideBlockageDetectorsHeight2 + frontSideBlockageDetectorsWidth2, transform.position + posChange2 + upHeight * 1.5f + forwardLength * 1.2f + (rightWidth / 4) + frontSideBlockageDetectorsForward2 + frontSideBlockageDetectorsHeight2 + frontSideBlockageDetectorsWidth2, out hit, collisionLayers) || !Physics.Raycast(transform.position + midSidePosChange + midSidePosChange + posChange2 + upHeight * 1.5f + forwardLength / 1.6f + (rightWidth / 4), upHeight, out hit, 2f, collisionLayers) || !Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.6f + (rightWidth / 4) + frontSideBlockageDetectorsHeight2 + frontSideBlockageDetectorsWidth2 + aboveHeadPlatformDetectorsForward2, transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.25f + (rightWidth / 4) + frontSideBlockageDetectorsHeight2 + frontSideBlockageDetectorsWidth2 + aboveHeadPlatformDetectorsForward2 + aboveHeadPlatformDetectorsHeight2, out hit, collisionLayers)) { rightMovable = false; } else { rightMovable = true; } } else { rightMovable = true; } //determines if your left side is blocked or not if (grabbedOn && (!switching || !ledgeSwitchingDetectors.allowLedgeSwitching) && Physics.Linecast(transform.position + posChange2 + upHeight - rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight - rightWidth * 1.35f + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + upHeight * 1.25f - rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight * 1.25f - rightWidth * 1.35f + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f - rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight * 1.5f - rightWidth * 1.35f + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + upHeight * 1.75f - rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight * 1.75f - rightWidth * 1.35f + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.75f - rightWidth + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2 - secondAllowRotatingIfLedgeHitWidth2, transform.position + posChange2 + upHeight * 0.8f - rightWidth + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2 - secondAllowRotatingIfLedgeHitWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.75f - rightWidth / 1.5f + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2 - firstAllowRotatingIfLedgeHitWidth2, transform.position + posChange2 + upHeight * 0.8f - rightWidth / 1.5f + preventRotatingToSideWallHeight2 - preventRotatingToSideWallWidth2 - firstAllowRotatingIfLedgeHitWidth2, out hit, collisionLayers)) { leftBlocked = true; } else if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit) { leftBlocked = false; } //determines if your right side is blocked or not if (grabbedOn && (!switching || !ledgeSwitchingDetectors.allowLedgeSwitching) && Physics.Linecast(transform.position + posChange2 + upHeight + rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight + rightWidth * 1.35f + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + upHeight * 1.25f + rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight * 1.25f + rightWidth * 1.35f + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight * 1.5f + rightWidth * 1.35f + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + upHeight * 1.75f + rightWidth / 10 + preventRotatingToSideWallHeight2, transform.position + posChange2 + upHeight * 1.75f + rightWidth * 1.35f + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.75f + rightWidth + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2 + secondAllowRotatingIfLedgeHitWidth2, transform.position + posChange2 + upHeight * 0.8f + rightWidth + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2 + secondAllowRotatingIfLedgeHitWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange2 + upHeight * 1.75f + rightWidth / 1.5f + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2 + firstAllowRotatingIfLedgeHitWidth2, transform.position + posChange2 + upHeight * 0.8f + rightWidth / 1.5f + preventRotatingToSideWallHeight2 + preventRotatingToSideWallWidth2 + firstAllowRotatingIfLedgeHitWidth2, out hit, collisionLayers)) { rightBlocked = true; } else if (((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit) { rightBlocked = false; } //checking to see if a surface can be climbed if (!Physics.Linecast(transform.position + posChange1 + ((transform.up + nonLedgeSurfaceDetectorsHeight2) * height2) * 0.3f, transform.position + posChange1 + ((transform.up + nonLedgeSurfaceDetectorsHeight2) * height2) * 0.1f + forwardLength + nonLedgeSurfaceDetectorsForward2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange1 + ((transform.up + nonLedgeSurfaceDetectorsHeight2) * height2) * 0.6f, transform.position + posChange1 + ((transform.up + nonLedgeSurfaceDetectorsHeight2) * height2) * 0.6f + forwardLength / 2.5f + nonLedgeSurfaceDetectorsForward2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange1 + ((transform.up + nonLedgeSurfaceDetectorsHeight2) * height2) * 0.8f, transform.position + posChange1 + ((transform.up + nonLedgeSurfaceDetectorsHeight2) * height2) * 0.8f + forwardLength / 2.3f + nonLedgeSurfaceDetectorsForward2, out hit, collisionLayers) || grabbedOn) { //checking to see if a surface directly in front of the player can be climbed if (Physics.Linecast(transform.position + posChange2 + upHeight, transform.position + posChange2 + upHeight + forwardLength / 1.25f + upHeight * 1.5f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2), out hit, collisionLayers) || Physics.Linecast(transform.position + posChange2 + upHeight + forwardLength / 1.25f + upHeight * 1.5f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2), transform.position + posChange2 + upHeight + forwardLength + upHeight * 1.25f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2), out hit, collisionLayers)) { climbable = false; } else if (Physics.Linecast(transform.position + posChange2 + upHeight / 2 + forwardLength / 1.52f + upHeight * 0.9f + (ledgeDetectorHeight2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f)) + (ledgeDetectorForward2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f))) + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2 + transform.forward * (topOfLedgeSurfaceDetectorHeight2 * length2) * 0.14f + transform.up * (topOfLedgeSurfaceDetectorHeight2 * height2)), transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f + (ledgeDetectorHeight2 + ledgeDetectorForward2 + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2), out hit, collisionLayers) && angle <= ledgeAngleLimit) { climbable = true; hitPoint = hit.point; } else { climbable = false; } //checking to see if a surface to the left of the player can be climbed if (Physics.Linecast(transform.position + posChange2 + upHeight - rightWidth / 4, transform.position + posChange2 + upHeight + forwardLength / 1.25f + upHeight * 1.5f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) - rightWidth / 4, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange2 + upHeight + forwardLength / 1.25f + upHeight * 1.5f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) - rightWidth / 4, transform.position + posChange2 + upHeight + forwardLength + upHeight * 1.25f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) - rightWidth / 4, out hit, collisionLayers)) { climbableL = false; } else if (Physics.Linecast(transform.position + posChange2 + upHeight / 2 + forwardLength / 1.52f + upHeight * 0.9f + (ledgeDetectorHeight2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f)) + (ledgeDetectorForward2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f))) + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2 + transform.forward * (topOfLedgeSurfaceDetectorHeight2 * length2) * 0.14f + transform.up * (topOfLedgeSurfaceDetectorHeight2 * height2)) - rightWidth / 4, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f + (ledgeDetectorHeight2 + ledgeDetectorForward2 + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) - rightWidth / 4, out hit, collisionLayers) && angle <= ledgeAngleLimit) { climbableL = true; } else { climbableL = false; } //checking to see if a surface to the right of the player can be climbed if (Physics.Linecast(transform.position + posChange2 + upHeight + rightWidth / 4, transform.position + posChange2 + upHeight + forwardLength / 1.25f + upHeight * 1.5f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) + rightWidth / 4, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange2 + upHeight + forwardLength / 1.25f + upHeight * 1.5f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) + rightWidth / 4, transform.position + posChange2 + upHeight + forwardLength + upHeight * 1.25f + (rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) + rightWidth / 4, out hit, collisionLayers)) { climbableR = false; } else if (Physics.Linecast(transform.position + posChange2 + upHeight / 2 + forwardLength / 1.52f + upHeight * 0.9f + (ledgeDetectorHeight2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f)) + (ledgeDetectorForward2 * (0.65f - (topOfLedgeSurfaceDetectorHeight2 * 0.59f))) + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2 + transform.forward * (topOfLedgeSurfaceDetectorHeight2 * length2) * 0.14f + transform.up * (topOfLedgeSurfaceDetectorHeight2 * height2)) + rightWidth / 4, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f + (ledgeDetectorHeight2 + ledgeDetectorForward2 + rodHoldingLedgeDetectorHeight2 + rodHoldingLedgeDetectorForward2) + rightWidth / 4, out hit, collisionLayers) && angle <= ledgeAngleLimit) { climbableR = true; } else { climbableR = false; } } else { climbable = false; climbableL = false; climbableR = false; } //getting angle of ledge player is grabbed on to if (climbPossibleL && climbPossibleR && (!switching || !ledgeSwitchingDetectors.allowLedgeSwitching)) { if (Physics.Linecast(transform.position + posChange2 + upHeight * 1.5f + forwardLength / 1.7f + underPlatformMaxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.7f, out hit, collisionLayers)) { if (hasNotMovedOnLedgeAsideFromLedgeSwitchingYet) { ledgeAngle = Vector3.Angle(transform.right, hit.normal) - 90; } else { ledgeAngle = Mathf.Lerp(ledgeAngle, Vector3.Angle(transform.right, hit.normal) - 90, 6 * Time.deltaTime); } } else if (Physics.Linecast(transform.position + posChange2 + upHeight * 2.2f + forwardLength / 1.75f + maxSurfaceLevelHeight2, transform.position + posChange2 + upHeight * 0.8f + forwardLength / 1.75f, out hit, collisionLayers)) { if (hasNotMovedOnLedgeAsideFromLedgeSwitchingYet) { ledgeAngle = Vector3.Angle(transform.right, hit.normal) - 90; } else { ledgeAngle = Mathf.Lerp(ledgeAngle, Vector3.Angle(transform.right, hit.normal) - 90, 6 * Time.deltaTime); } } } //determining whether you are grounded or not Vector3 pos = transform.position; pos.y = GetComponent<Collider>().bounds.min.y + 0.1f; if (Physics.Raycast(pos, Vector3.down, maxGroundedDistance, collisionLayers) || Physics.Raycast(pos - transform.forward / 10, Vector3.down, maxGroundedDistance, collisionLayers) || Physics.Raycast(pos + transform.forward / 10, Vector3.down, maxGroundedDistance, collisionLayers) || Physics.Raycast(pos - transform.right / 10, Vector3.down, maxGroundedDistance, collisionLayers) || Physics.Raycast(pos + transform.right / 10, Vector3.down, maxGroundedDistance, collisionLayers)) { currentStatesOfVariables.grounded = true; } else { currentStatesOfVariables.grounded = false; } //getting the direction of the joystick/arrow keys directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); if (directionVector != Vector3.zero) { //getting the length of the direction vector and normalizing it float directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; //setting the maximum direction length to 1 directionLength = Mathf.Min(1, directionLength); directionLength *= directionLength; //multiply the normalized direction vector by the modified direction length directionVector *= directionLength; } if (!turnBack) { ledgeJumpPossible = true; //checking to see if either side of a ledge is blocked if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) { if (currentStatesOfVariables.grounded && !climbable && !Physics.Linecast(transform.position + posChange1 + upHeight * 0.5f, transform.position + posChange1 + forwardLength / 1.5f + upHeight * 0.5f + spaceInFrontNeededToGrabBackOn2, out hit, collisionLayers) && !back2 && !grabbedOn && !pullingUp) { if (!Physics.Linecast(transform.position + posChange1 + forwardLength / 4 + upHeight * 0.5f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight * 1.5f - spaceBelowNeededToGrabBackOnHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + forwardLength / 1.5f + upHeight * 0.5f + spaceInFrontNeededToGrabBackOn2, transform.position + posChange1 + forwardLength / 1.5f - upHeight * 1.5f + spaceInFrontNeededToGrabBackOn2 - spaceBelowNeededToGrabBackOnHeight2, out hit, collisionLayers) || canJumpOffLedge && walkingOffLedgeDetectors.allowJumpingOffLedges) { if (!Physics.Linecast(transform.position + posChange1 + forwardLength / 4 + upHeight * 0.5f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight * 1.5f - spaceBelowNeededToGrabBackOnHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + forwardLength / 1.5f + upHeight * 0.5f + spaceInFrontNeededToGrabBackOn2, transform.position + posChange1 + forwardLength / 1.5f - upHeight * 1.5f + spaceInFrontNeededToGrabBackOn2 - spaceBelowNeededToGrabBackOnHeight2, out hit, collisionLayers)) { nonJumpTurnAround = true; } else { nonJumpTurnAround = false; } //if left is blocked, go to back right if ((Physics.Linecast(transform.position + posChange1 + forwardLength / 4 - upHeight * 0.1f + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 2 - upHeight * 0.1f - rightWidth / 4 + sideLedgeDetectorsLength2 + firstSideLedgeDetectorsHeight2 - sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 2 - upHeight * 0.1f - rightWidth / 4 + sideLedgeDetectorsLength2 + firstSideLedgeDetectorsHeight2 - sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight * 0.1f + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange1 + forwardLength / 4 - upHeight * 0.5f + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 2 - upHeight * 0.5f - rightWidth / 4 + sideLedgeDetectorsLength2 + secondSideLedgeDetectorsHeight2 - sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 3 - upHeight * 0.5f + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength / 4 - upHeight * 0.5f + rightWidth / 4 - sideLedgeDetectorsLength2 + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 2 - upHeight * 0.5f - rightWidth / 4 + sideLedgeDetectorsLength2 + secondSideLedgeDetectorsHeight2 - sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight * 0.5f + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange1 + forwardLength / 4 - upHeight + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 2 - rightWidth / 4 + sideLedgeDetectorsLength2 - upHeight + thirdSideLedgeDetectorsHeight2 - sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 3 - upHeight + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength / 4 - upHeight + rightWidth / 4 - sideLedgeDetectorsLength2 + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 2 - rightWidth / 4 + sideLedgeDetectorsLength2 - upHeight + thirdSideLedgeDetectorsHeight2 - sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers)) && Physics.Linecast(transform.position + posChange1 + forwardLength / 3 - upHeight * 0.1f + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength / 4 - upHeight * 0.1f + rightWidth / 4 - sideLedgeDetectorsLength2 + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers)) { if (Physics.Raycast(transform.position + midSidePosChange + posChange1 - upHeight / 9 + forwardLength, -forwardLength / 4, out hit, 3f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { backRotation = Quaternion.LookRotation(-hit.normal); } else if (Physics.Raycast(transform.position + midSidePosChange + posChange1 - upHeight / 20 + forwardLength, -forwardLength / 4, out hit, 3f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { backRotation = Quaternion.LookRotation(-hit.normal); } else { backRotation = Quaternion.LookRotation(-transform.forward, Vector3.up); } angleBetweenPlayerAndTurnBackWall = Vector3.Angle(transform.right, hit.normal); if (Physics.Linecast(transform.position + posChange1 + upHeight - forwardLength / 3 + rightWidth * 0.4f + grabBackOnLocationForward2 + grabBackOnLocationWidth2 + grabBackOnLocationHeight2, transform.position + posChange1 - upHeight - forwardLength / 3 + rightWidth * 0.4f + grabBackOnLocationForward2 + grabBackOnLocationWidth2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit) { backPoint = new Vector3(hit.point.x + transform.forward.x * length2, hit.point.y - (height2 * 1.15f), hit.point.z + transform.forward.z * length2); playerPosY = backPoint.y; turnBackRight = true; turnBackLeft = false; turnBackMiddle = false; turnBack = true; } else if (Physics.Linecast(transform.position + posChange1 + upHeight - forwardLength / 2 + rightWidth * 0.4f + grabBackOnLocationForward2 + grabBackOnLocationWidth2 + grabBackOnLocationHeight2, transform.position + posChange1 - upHeight - forwardLength / 2 + rightWidth * 0.4f + grabBackOnLocationForward2 + grabBackOnLocationWidth2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit) { backPoint = new Vector3(hit.point.x + transform.forward.x * length2, hit.point.y - (height2 * 1.15f), hit.point.z + transform.forward.z * length2); playerPosY = backPoint.y; turnBackRight = true; turnBackLeft = false; turnBackMiddle = false; turnBack = true; } } //if right is blocked, go to back left else if ((Physics.Linecast(transform.position + posChange1 + forwardLength / 4 - upHeight * 0.1f + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 2 - upHeight * 0.1f + rightWidth / 4 + sideLedgeDetectorsLength2 + firstSideLedgeDetectorsHeight2 + sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 2 - upHeight * 0.1f + rightWidth / 4 + sideLedgeDetectorsLength2 + firstSideLedgeDetectorsHeight2 + sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight * 0.1f + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange1 + forwardLength / 4 - upHeight * 0.5f + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 2 - upHeight * 0.5f + rightWidth / 4 + sideLedgeDetectorsLength2 + secondSideLedgeDetectorsHeight2 + sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 3 - upHeight * 0.5f + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength / 4 - upHeight * 0.5f - rightWidth / 4 - sideLedgeDetectorsLength2 + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 2 - upHeight * 0.5f + rightWidth / 4 + sideLedgeDetectorsLength2 + secondSideLedgeDetectorsHeight2 + sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight * 0.5f + secondSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) || Physics.Linecast(transform.position + posChange1 + forwardLength / 4 - upHeight + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 2 + rightWidth / 4 + sideLedgeDetectorsLength2 - upHeight + thirdSideLedgeDetectorsHeight2 + sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 3 - upHeight + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength / 4 - upHeight - rightWidth / 4 - sideLedgeDetectorsLength2 + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + forwardLength / 2 + rightWidth / 4 + sideLedgeDetectorsLength2 - upHeight + thirdSideLedgeDetectorsHeight2 + sideLedgeDetectorsWidth2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 + forwardLength / 4 - upHeight + thirdSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers)) && Physics.Linecast(transform.position + posChange1 + forwardLength / 3 - upHeight * 0.1f + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength / 4 - upHeight * 0.1f - rightWidth / 4 - sideLedgeDetectorsLength2 + firstSideLedgeDetectorsHeight2 + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers)) { if (Physics.Raycast(transform.position + midSidePosChange + posChange1 - upHeight / 9 + forwardLength, -forwardLength / 4, out hit, 3f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { backRotation = Quaternion.LookRotation(-hit.normal); } else if (Physics.Raycast(transform.position + midSidePosChange + posChange1 - upHeight / 20 + forwardLength, -forwardLength / 4, out hit, 3f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { backRotation = Quaternion.LookRotation(-hit.normal); } else { backRotation = Quaternion.LookRotation(-transform.forward, Vector3.up); } angleBetweenPlayerAndTurnBackWall = Vector3.Angle(transform.right, hit.normal); if (Physics.Linecast(transform.position + posChange1 + upHeight - forwardLength / 3 - rightWidth * 0.4f + grabBackOnLocationForward2 - grabBackOnLocationWidth2 + grabBackOnLocationHeight2, transform.position + posChange1 - upHeight - forwardLength / 3 - rightWidth * 0.4f + grabBackOnLocationForward2 - grabBackOnLocationWidth2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit) { backPoint = new Vector3(hit.point.x + transform.forward.x * length2, hit.point.y - (height2 * 1.15f), hit.point.z + transform.forward.z * length2); playerPosY = backPoint.y; turnBackLeft = true; turnBackRight = false; turnBackMiddle = false; turnBack = true; } else if (Physics.Linecast(transform.position + posChange1 + upHeight - forwardLength / 2 - rightWidth * 0.4f + grabBackOnLocationForward2 - grabBackOnLocationWidth2 + grabBackOnLocationHeight2, transform.position + posChange1 - upHeight - forwardLength / 2 - rightWidth * 0.4f + grabBackOnLocationForward2 - grabBackOnLocationWidth2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit) { backPoint = new Vector3(hit.point.x + transform.forward.x * length2, hit.point.y - (height2 * 1.15f), hit.point.z + transform.forward.z * length2); playerPosY = backPoint.y; turnBackLeft = true; turnBackRight = false; turnBackMiddle = false; turnBack = true; } } //if neither side is blocked, go directly back else if ((Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45 || Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45 || Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45 || Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45 || Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45 || Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) && !Physics.Linecast(new Vector3((hit.point + hit.normal / (3.5f / length2)).x, transform.position.y + upHeight.y * 0.5f, (hit.point + hit.normal / (3.5f / length2)).z), new Vector3((hit.point + hit.normal / (3.5f / length2)).x, transform.position.y - upHeight.y * 1.5f - spaceBelowNeededToGrabBackOnHeight2.y, (hit.point + hit.normal / (3.5f / length2)).z), out hit, collisionLayers)) { if (Physics.Raycast(transform.position + midSidePosChange + posChange1 - upHeight / 9 + forwardLength, -forwardLength / 4, out hit, 3f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { backRotation = Quaternion.LookRotation(-hit.normal); } else if (Physics.Raycast(transform.position + midSidePosChange + posChange1 - upHeight / 20 + forwardLength, -forwardLength / 4, out hit, 3f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { backRotation = Quaternion.LookRotation(-hit.normal); } else { backRotation = Quaternion.LookRotation(-transform.forward, Vector3.up); } angleBetweenPlayerAndTurnBackWall = Vector3.Angle(transform.right, hit.normal); if (Physics.Linecast(transform.position + posChange1 + upHeight - forwardLength / 2 + grabBackOnLocationForward2 + grabBackOnLocationHeight2, transform.position + posChange1 - upHeight - forwardLength / 2 + grabBackOnLocationForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) <= ledgeAngleLimit) { backPoint = new Vector3(hit.point.x + transform.forward.x * length2, hit.point.y - (height2 * 1.15f), hit.point.z + transform.forward.z * length2); playerPosY = backPoint.y; turnBackMiddle = true; turnBackLeft = false; turnBackRight = false; turnBack = true; } } else { turnBackMiddle = false; turnBackLeft = false; turnBackRight = false; turnBack = false; } //if player can jump off ledge, jump if (canJumpOffLedge && walkingOffLedgeDetectors.allowJumpingOffLedges) { turnBack = true; } } } //getting the position to lerp to when walking off a ledge if (turnBackMiddle) { if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else { turnBackPoint = new Vector3(backPoint.x - transform.forward.x * length2 / 15, (playerPosY + onLedgeHeight2 / 10), backPoint.z - transform.forward.z * length2 / 15); } } else if (turnBackLeft) { if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 - rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else { turnBackPoint = new Vector3(backPoint.x - transform.forward.x * length2 / 15, (playerPosY + onLedgeHeight2 / 10), backPoint.z - transform.forward.z * length2 / 15); } } else if (turnBackRight) { if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.25f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.05f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.15f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else if (Physics.Linecast(transform.position + posChange1 + forwardLength / 3.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, transform.position + posChange1 - forwardLength * 0.5f - upHeight * 0.25f + spaceBelowNeededToGrabBackOnForward2 + rightWidth * 0.4f, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > 45) { turnBackPoint = hit.point + hit.normal / (3.5f / length2); } else { turnBackPoint = new Vector3(backPoint.x - transform.forward.x * length2 / 15, (playerPosY + onLedgeHeight2 / 10), backPoint.z - transform.forward.z * length2 / 15); } } } } //turning around when you walk off an edge if (turnBack) { if (walkingOffLedgeDetectors.allowJumpingOffLedges && directionVector.magnitude >= walkingOffLedgeDetectors.inputPercentageNeededToJump / 100 && ledgeJumpPossible) { back2 = false; grabbedOn = false; pullingUp = false; getOn = false; getOn2 = false; jumpDir = (transform.forward * walkingOffLedgeDetectors.jumpDistance) + (transform.up * walkingOffLedgeDetectors.jumpHeight); turnBack = false; } else if (walkingOffLedgeDetectors.allowGrabbingBackOnToLedges && nonJumpTurnAround && (turnBackMiddle || turnBackLeft || turnBackRight)) { jumpDir = Vector3.zero; ledgeJumpPossible = false; if (!stayUpright) { turnBackTimer = 0.0f; if (Vector3.Distance(transform.position, new Vector3(turnBackPoint.x, (playerPosY + onLedgeHeight2 / 10), turnBackPoint.z)) > 0.3f || Quaternion.Angle(transform.rotation, backRotation) > 0.1f) { back2 = false; grabbedOn = false; pullingUp = false; getOn = false; getOn2 = false; if (GetComponent<CharacterController>() && GetComponent<CharacterController>().enabled) { transform.position = Vector3.Lerp(transform.position, new Vector3(turnBackPoint.x, (playerPosY + onLedgeHeight2 / 10), turnBackPoint.z), 10 * Time.deltaTime); } else if (GetComponent<Rigidbody>()) { transform.position = Vector3.Lerp(transform.position, new Vector3(turnBackPoint.x, (playerPosY + onLedgeHeight2 / 10), turnBackPoint.z), 10 * Time.deltaTime); } transform.rotation = Quaternion.Slerp(transform.rotation, backRotation, 12 * Time.deltaTime); playerPosXZ = transform.position + posChange2; } else { back2 = true; turnBack = false; } } else { if (Vector3.Distance(transform.position, new Vector3(turnBackPoint.x, (playerPosY + onLedgeHeight2 / 10), turnBackPoint.z)) > 0.3f && turnBackTimer < 0.5f || Quaternion.Angle(transform.rotation, backRotation) > 0.1f && turnBackTimer < 0.5f) { turnBackTimer += 0.02f; back2 = false; grabbedOn = false; pullingUp = false; getOn = false; getOn2 = false; if (GetComponent<CharacterController>() && GetComponent<CharacterController>().enabled) { transform.position = Vector3.Lerp(transform.position, new Vector3(turnBackPoint.x, (playerPosY + onLedgeHeight2 / 10), turnBackPoint.z), 10 * Time.deltaTime); } else if (GetComponent<Rigidbody>()) { transform.position = Vector3.Lerp(transform.position, new Vector3(turnBackPoint.x, (playerPosY + onLedgeHeight2 / 10), turnBackPoint.z), 10 * Time.deltaTime); } transform.rotation = Quaternion.Slerp(transform.rotation, backRotation, 12 * Time.deltaTime); playerPosXZ = transform.position + posChange2; } else { turnBackTimer = 0.0f; back2 = true; turnBack = false; } } } else { back2 = false; turnBack = false; } } if (walkingOffLedgeDetectors.allowGrabbingBackOnToLedges) { if (back2) { turnBack = false; if (!grabbedOn) { transform.position = new Vector3(playerPosXZ.x, (playerPosY + onLedgeHeight2 / 10), playerPosXZ.z); grabbedOn = true; } } if (turnBack || back2) { movementSpeed = 0; if (Input.GetButtonDown("Jump")) { if (scriptsToDisableOnGrab != null) { foreach (string script in scriptsToDisableOnGrab) { scriptToDisable = GetComponent(script) as MonoBehaviour; if (scriptToDisable != null) { scriptToDisable.enabled = true; } else if (!currentlyEnablingAndDisablingScripts || turnBack) { scriptWarning = true; } } } if (scriptsToEnableOnGrab != null) { foreach (string script in scriptsToEnableOnGrab) { scriptToEnable = GetComponent(script) as MonoBehaviour; if (scriptToEnable != null) { scriptToEnable.enabled = false; } else if (!currentlyEnablingAndDisablingScripts || turnBack) { scriptWarning = true; } } } currentlyEnablingAndDisablingScripts = true; jumpedOffTimer = 0; jumpedOffDirection = -transform.forward * distanceToPushOffOfLedgeAfterLettingGo; if (GetComponent<Animator>()) { GetComponent<Animator>().speed = 1; } getOn = false; getOn2 = false; pullingUp = false; grabbedOn = false; turnBack = false; } else { if (scriptsToDisableOnGrab != null) { foreach (string script in scriptsToDisableOnGrab) { scriptToDisable = GetComponent(script) as MonoBehaviour; if (scriptToDisable != null) { scriptToDisable.enabled = false; } else if (!currentlyEnablingAndDisablingScripts) { scriptWarning = true; } } } if (scriptsToEnableOnGrab != null) { foreach (string script in scriptsToEnableOnGrab) { scriptToEnable = GetComponent(script) as MonoBehaviour; if (scriptToEnable != null) { scriptToEnable.enabled = true; } else if (!currentlyEnablingAndDisablingScripts) { scriptWarning = true; } } } currentlyEnablingAndDisablingScripts = true; } } } //jumping off of ledges if (inAirFromJumpingOffLedge && noCollisionTimer >= 2 || inAirFromJumpingOffLedge && !currentStatesOfVariables.grounded && !walkingOffLedgeDetectors.disableScriptsWhileJumping) { inAirFromJumpingOffLedgeNoCollision = true; } if (inAirFromJumpingOffLedgeNoCollision && noCollisionTimer < 2 || jumpDir == Vector3.zero) { inAirFromJumpingOffLedgeNoCollision = false; } yPosDiff = transform.position.y - lastYPos; lastYPos = transform.position.y; if (GetComponent<CharacterController>() && GetComponent<CharacterController>().enabled) { vel = GetComponent<CharacterController>().velocity; } else if (GetComponent<Rigidbody>()) { vel = GetComponent<Rigidbody>().velocity; } if (Physics.Raycast(pos, Vector3.down, out hit, 1f, collisionLayers) && noCollisionTimer < 5 && currentStatesOfVariables.grounded || (Physics.Raycast(pos, Vector3.down, out hit, 1f, collisionLayers) && noCollisionTimer < 5 || currentStatesOfVariables.grounded) && GetComponent<Rigidbody>()) { if (inAirFromJumpingOffLedge && !walkingOffLedgeDetectors.disableScriptsWhileJumping) { inAirFromJumpingOffLedge = false; jumpDir = Vector3.zero; } } if (Vector3.Distance(jumpDir, Vector3.zero) > 0.1f && yPosDiff * 5 < 1 * (walkingOffLedgeDetectors.jumpHeight / 7) || inAirFromJumpingOffLedgeNoCollision && yPosDiff * 5 < 1 * (walkingOffLedgeDetectors.jumpHeight / 7)) { turnBack = false; if (!currentStatesOfVariables.grounded) { jumpDust = true; inAirFromJumpingOffLedge = true; } if (inAirFromJumpingOffLedge) { if (walkingOffLedgeDetectors.disableScriptsWhileJumping && vel.y != 0) { if (scriptsToDisableOnGrab != null) { foreach (string script in scriptsToDisableOnGrab) { scriptToDisable = GetComponent(script) as MonoBehaviour; if (scriptToDisable != null) { scriptToDisable.enabled = false; } else if (!currentlyEnablingAndDisablingScripts) { scriptWarning = true; } } } if (scriptsToEnableOnGrab != null) { foreach (string script in scriptsToEnableOnGrab) { scriptToEnable = GetComponent(script) as MonoBehaviour; if (scriptToEnable != null) { scriptToEnable.enabled = true; } else if (!currentlyEnablingAndDisablingScripts) { scriptWarning = true; } } } currentlyEnablingAndDisablingScripts = true; } if (!climbable || !climbPossible) { jumpDir.x = Mathf.Lerp(jumpDir.x, 0, walkingOffLedgeDetectors.jumpDecelerationRate * Time.deltaTime); jumpDir.z = Mathf.Lerp(jumpDir.z, 0, walkingOffLedgeDetectors.jumpDecelerationRate * Time.deltaTime); if (walkingOffLedgeDetectors.useGravity) { jumpDir.y -= walkingOffLedgeDetectors.gravity * Time.deltaTime; } if (GetComponent<CharacterController>() && GetComponent<CharacterController>().enabled) { GetComponent<CharacterController>().Move(jumpDir * Time.deltaTime); } else if (GetComponent<Rigidbody>()) { GetComponent<Rigidbody>().MovePosition(transform.position + jumpDir * Time.deltaTime); } } else { jumpDir = Vector3.zero; } } else { inAirFromJumpingOffLedge = false; } if (currentStatesOfVariables.grounded || !currentStatesOfVariables.grounded && !inAirFromJumpingOffLedge && !grabbedOn || !currentStatesOfVariables.grounded && climbable && climbPossible && !grabbedOn || !inAirFromJumpingOffLedgeNoCollision) { if (!canJumpOffLedge && inAirFromJumpingOffLedge && (noCollisionTimer > 5 || !GetComponent<Rigidbody>())) { if (walkingOffLedgeDetectors.disableScriptsWhileJumping) { if (scriptsToDisableOnGrab != null) { foreach (string script in scriptsToDisableOnGrab) { scriptToDisable = GetComponent(script) as MonoBehaviour; if (scriptToDisable != null) { scriptToDisable.enabled = true; } else if (!currentlyEnablingAndDisablingScripts || jumpDir != Vector3.zero) { scriptWarning = true; } } } if (scriptsToEnableOnGrab != null) { foreach (string script in scriptsToEnableOnGrab) { scriptToEnable = GetComponent(script) as MonoBehaviour; if (scriptToEnable != null) { scriptToEnable.enabled = false; } else if (!currentlyEnablingAndDisablingScripts || jumpDir != Vector3.zero) { scriptWarning = true; } } } currentlyEnablingAndDisablingScripts = true; } inAirFromJumpingOffLedge = false; jumpDir = Vector3.zero; } } } else if (noCollisionTimer > 5 || !GetComponent<Rigidbody>()) { inAirFromJumpingOffLedge = false; jumpDir = Vector3.zero; } //creating the optional dust effect after landing a jump off of a ledge if (!inAirFromJumpingOffLedge && jumpDust && jumpLandingEffect2 != null && currentStatesOfVariables.grounded) { jumpDir = Vector3.zero; Instantiate(jumpLandingEffect2, transform.position + new Vector3(0, 0.05f, 0), jumpLandingEffect2.transform.rotation); jumpDust = false; } //checking to see if player's y position (if using a Rigidbody) is decreasing if (GetComponent<Rigidbody>()) { if (transform.position.y <= rbPosY && !pullingUp || GetComponent<Rigidbody>().velocity.y <= 0 && !pullingUp) { rbPosYIncreasing = false; } else { rbPosYIncreasing = true; } rbPosY = transform.position.y; //checking to see if player (if using a Rigidbody) is using "Use Gravity" if (GetComponent<Rigidbody>().useGravity && !grabbedOn && !pullingUp && !turnBack && !back2) { rbUsesGravity = true; } if (grabbedOn || pullingUp || turnBack || back2) { canChangeRbGravity = true; GetComponent<Rigidbody>().useGravity = false; } else if (rbUsesGravity && canChangeRbGravity) { GetComponent<Rigidbody>().useGravity = true; canChangeRbGravity = false; } if (!GetComponent<Rigidbody>().useGravity && !grabbedOn && !pullingUp && !turnBack && !back2) { rbUsesGravity = false; } } //checking to see if player has not completely grabbed on to a ledge yet if (turnBack || switching || !grabbedOn) { hasNotMovedOnLedgeYet = true; if (!switching || !ledgeSwitchingDetectors.allowLedgeSwitching) { hasNotMovedOnLedgeAsideFromLedgeSwitchingYet = true; } } if (grabbedOn) { back2 = false; //detect sides //left if (!Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers)) { if (!leftBlocked && leftMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength - (rightWidth / 2), transform.position + midSidePosChange + posChange2 + upHeight + forwardLength - (rightWidth / 2), out hit, collisionLayers) && !Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 + firstBackWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 - rightWidth + firstBackWallDetectorsForward2 + firstBackWallDetectorsWidth2, out hit, collisionLayers)) { lSide = hit.point; left = true; } else if (!leftBlocked && leftMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 + firstBackWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 - rightWidth + firstBackWallDetectorsForward2 + firstBackWallDetectorsWidth2, out hit, collisionLayers)) { lSide = hit.point; left = true; } else if (!leftBlocked && leftMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 2 + secondBackWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 2 - rightWidth + secondBackWallDetectorsForward2 + secondBackWallDetectorsWidth2, out hit, collisionLayers)) { lSide = hit.point; left = true; } //back vertical line else if (!leftBlocked && leftMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight * 1.2f - forwardLength / 1.75f + upHeight * 1.5f - (rightWidth / 2) + backTopOfLedgeSurfaceDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 2 - upHeight / 2 - (rightWidth / 2) + backTopOfLedgeSurfaceDetectorsForward2, out hit, collisionLayers)) { lSide = hit.point + rightWidth / 3; left = true; } //front vertical line else if (Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight * 1.2f + forwardLength / 1.25f + upHeight * 1.5f - (rightWidth / 2) + frontTopOfLedgeSurfaceDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight + forwardLength / 1.75f - upHeight / 2 - (rightWidth / 2) + frontTopOfLedgeSurfaceDetectorsForward2, out hit, collisionLayers)) { lSide = hit.point; left = true; } else if (Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight + forwardLength / 2 - (rightWidth / 2) + firstFrontWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight + forwardLength / 2 + rightWidth + firstFrontWallDetectorsForward2 + firstFrontWallDetectorsWidth2, out hit, collisionLayers)) { lSide = hit.point - rightWidth / 3; left = true; } else if (Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight + forwardLength - (rightWidth / 2) + secondFrontWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight + forwardLength + rightWidth + secondFrontWallDetectorsForward2 + secondFrontWallDetectorsWidth2, out hit, collisionLayers)) { lSide = hit.point - rightWidth / 3; left = true; } else { left = false; } } else { left = false; } //right if (!Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers)) { if (!rightBlocked && rightMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength + (rightWidth / 2), transform.position + midSidePosChange + posChange2 + upHeight + forwardLength + (rightWidth / 2), out hit, collisionLayers) && !Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 + firstBackWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 + rightWidth + firstBackWallDetectorsForward2 - firstBackWallDetectorsWidth2, out hit, collisionLayers)) { rSide = hit.point; right = true; } else if (!rightBlocked && rightMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 + firstBackWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 3 + rightWidth + firstBackWallDetectorsForward2 - firstBackWallDetectorsWidth2, out hit, collisionLayers)) { rSide = hit.point; right = true; } else if (!rightBlocked && rightMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 2 + secondBackWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 2 + rightWidth + secondBackWallDetectorsForward2 - secondBackWallDetectorsWidth2, out hit, collisionLayers)) { rSide = hit.point; right = true; } //back vertical line else if (!rightBlocked && rightMovable && Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight * 1.2f - forwardLength / 1.75f + upHeight * 1.5f + (rightWidth / 2) + backTopOfLedgeSurfaceDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight - forwardLength / 2 - upHeight / 2 + (rightWidth / 2) + backTopOfLedgeSurfaceDetectorsForward2, out hit, collisionLayers)) { rSide = hit.point - rightWidth / 3; right = true; } //front vertical line else if (Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight * 1.2f + forwardLength / 1.25f + upHeight * 1.5f + (rightWidth / 2) + frontTopOfLedgeSurfaceDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight + forwardLength / 1.75f - upHeight / 2 + (rightWidth / 2) + frontTopOfLedgeSurfaceDetectorsForward2, out hit, collisionLayers)) { rSide = hit.point; right = true; } else if (Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight + forwardLength / 2 + (rightWidth / 2) + firstFrontWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight + forwardLength / 2 - rightWidth + firstFrontWallDetectorsForward2 - firstFrontWallDetectorsWidth2, out hit, collisionLayers)) { rSide = hit.point + rightWidth / 3; right = true; } else if (Physics.Linecast(transform.position + midSidePosChange + posChange2 + upHeight + forwardLength + (rightWidth / 2) + secondFrontWallDetectorsForward2, transform.position + midSidePosChange + posChange2 + upHeight + forwardLength - rightWidth + secondFrontWallDetectorsForward2 - secondFrontWallDetectorsWidth2, out hit, collisionLayers)) { rSide = hit.point + rightWidth / 3; right = true; } else { right = false; } } else { right = false; } //checking to see if you are too close to the ground to go right or left if (Input.GetAxisRaw("Horizontal") > 0f && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers)) { movingRight = true; } else if (Input.GetAxisRaw("Horizontal") < 0f && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers)) { movingRight = false; } // left side out of ground if (!Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers)) { sL = false; } if (!Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers)) { sR = false; } if (movingRight && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers)) { sR = true; } else if (!movingRight && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers)) { sR = false; } if (!movingRight && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers)) { sL = true; } else if (movingRight && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers)) { sL = false; } if (sR && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers)) { left = true; right = false; } else if (sL && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers)) { left = false; right = true; } else if (!Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers)) { left = true; right = true; } else if (!Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 3 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers)) { left = true; right = true; } else { left = false; right = false; } //checking to see if sides are at a dead end if (!switching && !switchJumping || !ledgeSwitchingDetectors.allowLedgeSwitching) { if (!leftMovable) { if (!climbPossibleL || !climbPossible) { left = false; } } if (!rightMovable) { if (!climbPossibleR || !climbPossible) { right = false; } } } //checking to see if ledge is on level with, or above player if (Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength + rightWidth / 2, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + upHeight + midSidePosChange * 0.5f, forwardLength / 4 + rightWidth / 2, out hit, 0.7f, collisionLayers)) { upright = true; } else { upright = false; } if (Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength - rightWidth / 2, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + upHeight + midSidePosChange * 0.5f, forwardLength / 4 - rightWidth / 2, out hit, 0.7f, collisionLayers)) { upleft = true; } else { upleft = false; } if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength, out hit, 5f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, rightWidth / 4, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, -rightWidth / 4, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 + rightWidth / 4 - (upHeight + midSidePosChange), out hit, 1.5f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 - rightWidth / 4 - (upHeight + midSidePosChange), out hit, 1.5f, collisionLayers)) { upfront = true; } else { upfront = false; } RaycastHit hit2 = new RaycastHit(); if (Input.GetAxisRaw("Horizontal") > 0f && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, rightWidth / 2, out hit, 5f, collisionLayers) && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4, out hit2, 5f, collisionLayers) && Vector3.Distance(transform.position + transform.up, hit.point) < Vector3.Distance(transform.position, hit2.point)) { movingToSide = true; } else if (Input.GetAxisRaw("Horizontal") < 0f && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, -rightWidth / 2, out hit, 5f, collisionLayers) && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4, out hit2, 5f, collisionLayers) && Vector3.Distance(transform.position + transform.up, hit.point) < Vector3.Distance(transform.position, hit2.point)) { movingToSide = true; } else { movingToSide = false; } //rotation if (!switching || !ledgeSwitchingDetectors.allowLedgeSwitching) { //only change the rotation normal if player is moving if ((transform.rotation == lastRot3 || axisChanged) && (movementSpeed > 0 || Input.GetAxis("Horizontal") != 0) || hasNotMovedOnLedgeYet) { if (Physics.Raycast(transform.position + posChange2 + midSidePosChange * 0.5f, forwardLength / 4, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength + rightWidth / 2, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength - rightWidth / 2, out hit, 1f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { if (Physics.Raycast(transform.position + posChange2 + midSidePosChange, forwardLength / 4, out hit, 1f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else if (Physics.Raycast(transform.position + posChange2 + midSidePosChange * 0.8f, forwardLength / 4, out hit, 1f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else { rotationNormal = Quaternion.LookRotation(-hit.normal); } rotationState = 1; } else if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4, out hit, 5f, collisionLayers) && Vector3.Distance(transform.position + posChange2, hit.point) <= 1 && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 + rightWidth / 2, out hit, 5f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 - rightWidth / 2, out hit, 5f, collisionLayers) && !movingToSide && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange), forwardLength / 4, out hit, 5f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.8f, forwardLength / 4, out hit, 5f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else { rotationNormal = Quaternion.LookRotation(-hit.normal); } rotationState = 2; } else if (!rightBlocked && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 + rightWidth / 2, out hit, 0.7f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange), forwardLength / 4 + rightWidth / 2, out hit, 0.7f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.8f, forwardLength / 4 + rightWidth / 2, out hit, 0.7f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else { rotationNormal = Quaternion.LookRotation(-hit.normal); } rotationState = 3; } else if (!leftBlocked && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 - rightWidth / 2, out hit, 0.7f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange), forwardLength / 4 - rightWidth / 2, out hit, 0.7f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.8f, forwardLength / 4 - rightWidth / 2, out hit, 0.7f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else { rotationNormal = Quaternion.LookRotation(-hit.normal); } rotationState = 4; } else if (Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3, out hit, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength + rightWidth / 2, out hit, 5f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 2f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 5; } else if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength, out hit, 2f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength + rightWidth / 2, out hit, 5f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 2f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 6; } else if (!rightBlocked && Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f + rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 - rightWidth / 5, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f - rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 + rightWidth / 5, out hit, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 0.5f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 7; } else if (!rightBlocked && Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength + rightWidth / 2, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 0.5f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { if (Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength, out hit, 1f, collisionLayers)) { rotationNormal = Quaternion.LookRotation(-hit.normal); } else { rotationNormal = Quaternion.LookRotation(-hit.normal); } rotationState = 8; } else if (!rightBlocked && Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f + rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 - rightWidth / 5, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f - rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 + rightWidth / 5, out hit, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 2f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 9; } else if (!rightBlocked && Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength + rightWidth / 2, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 2f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 10; } else if (!leftBlocked && Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f - rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 + rightWidth / 5, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f - rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 + rightWidth / 5, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 11; } else if (!leftBlocked && Physics.Raycast(transform.position + midSidePosChange + posChange2 + upHeight * 1.1f, forwardLength - rightWidth / 2, out hit, 1f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 12; } else if (Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength, out hit, 1f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 13; } else if (!rightBlocked && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength + rightWidth / 2, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 0.5f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 14; } else if (!rightBlocked && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength + rightWidth / 2, out hit, 1f, collisionLayers) && !Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 2f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 15; } else if (!leftBlocked && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 1.1f, forwardLength - rightWidth / 2, out hit, 1f, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 16; } else if (!upfront && !rightBlocked && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 + rightWidth / 2 + (upHeight + midSidePosChange) * 0.5f, out hit, 0.7f, collisionLayers) && !upright && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 17; } else if (!upfront && !leftBlocked && Physics.Raycast(transform.position + posChange2 + (upHeight + midSidePosChange) * 0.5f, forwardLength / 4 - rightWidth / 2 + (upHeight + midSidePosChange) * 0.5f, out hit, 0.7f, collisionLayers) && !upleft && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 18; } else if (Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3f + rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 - rightWidth / 5, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 19; } else if (Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3f - rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 3 + rightWidth / 5, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 20; } else if (Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f + rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f - rightWidth / 5, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 21; } else if (Physics.Linecast(transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f - rightWidth / 5, transform.position + posChange1 + upHeight * 1.2f + forwardLength / 1.5f + rightWidth / 5, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) >= 45) { rotationNormal = Quaternion.LookRotation(-hit.normal); rotationState = 22; } else if (!left && !right) { rotationState = 23; if (scriptsToDisableOnGrab != null) { foreach (string script in scriptsToDisableOnGrab) { scriptToDisable = GetComponent(script) as MonoBehaviour; if (scriptToDisable != null) { scriptToDisable.enabled = true; } else if (!currentlyEnablingAndDisablingScripts || grabbedOn) { scriptWarning = true; } } } if (scriptsToEnableOnGrab != null) { foreach (string script in scriptsToEnableOnGrab) { scriptToEnable = GetComponent(script) as MonoBehaviour; if (scriptToEnable != null) { scriptToEnable.enabled = false; } else if (!currentlyEnablingAndDisablingScripts || grabbedOn) { scriptWarning = true; } } } currentlyEnablingAndDisablingScripts = true; if (GetComponent<Animator>()) { GetComponent<Animator>().speed = 1; } getOn = false; getOn2 = false; pullingUp = false; grabbedOn = false; } else { rotationState = 0; } if (movementSpeed > 0 || Input.GetAxis("Horizontal") != 0) { hasNotMovedOnLedgeYet = false; hasNotMovedOnLedgeAsideFromLedgeSwitchingYet = false; } } //checking to see if player changed their direction from left to right/right to left if ((Input.GetAxis("Horizontal") > 0 && horizontalAxis <= 0 || Input.GetAxis("Horizontal") < 0 && horizontalAxis >= 0)) { axisChanged = true; } else if (transform.rotation == lastRot3 && climbPossible && climbPossibleL && climbPossibleR) { axisChanged = false; } horizontalAxis = Input.GetAxis("Horizontal"); lastRot3 = transform.rotation; //rotating the player if (rotationState != 23 && rotationState != 0) { transform.rotation = Quaternion.Slerp(transform.rotation, rotationNormal, movingDetectors.rotationSpeed * Time.deltaTime); } //checking to see if player is leaning forward on a ledge wallInFrontAngle = Vector3.Angle(hit.normal, Vector3.up); if (wallInFrontAngle < 90) { leaningForward = true; } else { leaningForward = false; } } // if (grabbedOn && (!switching || !ledgeSwitchingDetectors.allowLedgeSwitching)) { //checking to see if left is hit/blocked if (Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers) && !sL) { transform.position += transform.right / 10; } //checking to see if right is hit/blocked if (Physics.Linecast(transform.position + posChange1 + upHeight + (rightWidth / 4) + minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 + (rightWidth / 4) + minDistFromGroundHeight2 + minDistFromGroundWidth2, out hit, collisionLayers) && !Physics.Linecast(transform.position + posChange1 + upHeight - (rightWidth / 4) - minDistFromGroundWidth2, transform.position + posChange1 - upHeight / 4 - (rightWidth / 4) + minDistFromGroundHeight2 - minDistFromGroundWidth2, out hit, collisionLayers) && !sR) { transform.position -= transform.right / 10; } } //checking to see if the angle of the surface (to the left or right) is greater than the angle limit if (Physics.Linecast(transform.position + posChange2 + forwardLength / 2f + upHeight * 1.5f - (rightWidth / 2) + ledgeAngleDetectorsHeight2 - ledgeAngleDetectorsWidth2, transform.position + posChange2 + upHeight + forwardLength / 2f - upHeight / 2 - (rightWidth / 2) - ledgeAngleDetectorsWidth2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 + forwardLength / 2f + upHeight * 1.5f - (rightWidth / 2) + ledgeAngleDetectorsHeight2 - ledgeAngleDetectorsWidth2, transform.position + posChange2 + upHeight * 1.5f + forwardLength - (rightWidth / 2) + ledgeAngleDetectorsHeight2 - ledgeAngleDetectorsWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + forwardLength / 2f + upHeight * 1.5f - (rightWidth / 1.85f) + ledgeAngleDetectorsHeight2 - ledgeAngleDetectorsWidth2, transform.position + posChange2 + upHeight + forwardLength / 2f - upHeight / 2 - (rightWidth / 1.85f) - ledgeAngleDetectorsWidth2, out hit, collisionLayers)) { left = false; angledLeft = true; } else { angledLeft = false; } if (Physics.Linecast(transform.position + posChange2 + forwardLength / 2f + upHeight * 1.5f + (rightWidth / 2) + ledgeAngleDetectorsHeight2 + ledgeAngleDetectorsWidth2, transform.position + posChange2 + upHeight + forwardLength / 2f - upHeight / 2 + (rightWidth / 2) + ledgeAngleDetectorsWidth2, out hit, collisionLayers) && ((Mathf.Acos(Mathf.Clamp(hit.normal.y, -1f, 1f))) * 57.2958f) > ledgeAngleLimit && !Physics.Linecast(transform.position + posChange2 + forwardLength / 2f + upHeight * 1.5f + (rightWidth / 2) + ledgeAngleDetectorsHeight2 + ledgeAngleDetectorsWidth2, transform.position + posChange2 + upHeight * 1.5f + forwardLength + (rightWidth / 2) + ledgeAngleDetectorsHeight2 + ledgeAngleDetectorsWidth2, out hit, collisionLayers) && Physics.Linecast(transform.position + posChange2 + forwardLength / 2f + upHeight * 1.5f + (rightWidth / 1.85f) + ledgeAngleDetectorsHeight2 + ledgeAngleDetectorsWidth2, transform.position + posChange2 + upHeight + forwardLength / 2f - upHeight / 2 + (rightWidth / 1.85f) + ledgeAngleDetectorsWidth2, out hit, collisionLayers)) { right = false; angledRight = true; } else { angledRight = false; } } //if stayUpright is true, only rotate to the left and right if (grabbedOn || pullingUp || turnBack || back2) { if (stayUpright && !leaningForward) { transform.eulerAngles = new Vector3(0f, transform.eulerAngles.y, 0f); } } //determining if an axis (horizontal or vertical) is being used to grab on to a ledge LedgeGrabbingAxisDetection(); //letting go of a ledge DropOffLedge(); //pushing off of wall after letting go of ledge PushOffLedge(); //getting information for ledge switching switchHitPoint = new RaycastHit(); GetLedgeSwitchInfo(); //if player is grabbed on to a ledge if (grabbedOn) { //enabling and disabling scripts EnableAndDisableScripts(); if (getOn) { transform.position = new Vector3(playerPosXZ.x, (playerPosY + onLedgeHeight2 / 10), playerPosXZ.z); getOn = false; } //moving to the left LeftMovement(); //moving to the right RightMovement(); //not moving to either side if (Input.GetAxis("Horizontal") == 0) { movementSpeed = 0; } } //pulling up over a ledge ClimbingOverLedge(); //when scripts are being enabled or disabled, warn the user if any script names they entered do not exist on the player ScriptWarning(); //making sure player is not stuck on a collider CheckIfStuck(); //animations if (GetComponent<Animator>()) { animator = GetComponent<Animator>(); //animating grabbing back on to a ledge after walking off if (turnBack && !turnedBackToLedge && walkingOffLedgeDetectors.allowGrabbingBackOnToLedges && nonJumpTurnAround) { //if the angle between the player and wall we are grabbing back on to is less than 90, turn to the left if (angleBetweenPlayerAndTurnBackWall < 90) { animator.SetFloat("ledgeState", 1); } //if the angle between the player and wall we are grabbing back on to is greater than or equal to 90, turn to the right else { animator.SetFloat("ledgeState", 2); } animator.CrossFade("LedgeMovement", 0f, -1, 0f); turnedBackToLedge = true; } else if (!turnBack && !back2 && turnedBackToLedge && Input.GetAxis("Horizontal") != 0) { turnedBackToLedge = false; } if (switching) { animator.speed = (ledgeSwitchingDetectors.switchJumpSpeed / switchPointDist * 3) / 4; } if (grabbedOn && !turnedBackToLedge) { if (!animator.GetBool("onLedge")) { animator.SetBool("onLedge", true); } if (!switchJumping) { animator.SetFloat("ledgeAngle", ledgeAngle); if (Input.GetAxis("Horizontal") > 0 && movingDetectors.moveSpeed > 0) { animator.speed = ((movingDetectors.moveSpeed / 3) / movingDetectors.burstLength) / ((movingDetectors.moveSpeed * 2) / (3 + movingDetectors.moveSpeed)); //animating moving to the right while grabbed on to a ledge if (!switching) { if (right && !stuckToRight) { if (animator.GetFloat("ledgeSpeed") != 1 || movementSpeed < 0.1f) { animator.CrossFade("LedgeMovement", 0f, -1, 0f); animator.SetFloat("ledgeSpeed", 1); } } else { //stopping player's movement and keeping him from moving to the right animator.speed = 1; if (animator.GetFloat("ledgeSpeed") == 1) { movementSpeed = 0; } animator.SetFloat("ledgeSpeed", Mathf.Lerp(animator.GetFloat("ledgeSpeed"), 0, ((((movingDetectors.moveSpeed / 3) / movingDetectors.burstLength) / ((movingDetectors.moveSpeed * 2) / (3 + movingDetectors.moveSpeed))) * 12) * Time.deltaTime)); } } //animating switching to a ledge on the right side of the player else if (animator.GetFloat("ledgeSpeed") != 2 && !switchJumping) { animator.speed = (ledgeSwitchingDetectors.switchJumpSpeed / switchPointDist * 3) / 4; animator.CrossFade("LedgeMovement", 0f, -1, 0f); animator.SetFloat("ledgeSpeed", 2); } } else if (Input.GetAxis("Horizontal") < 0 && movingDetectors.moveSpeed > 0) { animator.speed = ((movingDetectors.moveSpeed / 3) / movingDetectors.burstLength) / ((movingDetectors.moveSpeed * 2) / (3 + movingDetectors.moveSpeed)); //animating moving to the left while grabbed on to a ledge if (!switching) { if (left && !stuckToLeft) { if (animator.GetFloat("ledgeSpeed") != -1 || movementSpeed < 0.1f) { animator.CrossFade("LedgeMovement", 0f, -1, 0f); animator.SetFloat("ledgeSpeed", -1); } } else { //stopping player's movement and keeping him from moving to the left animator.speed = 1; if (animator.GetFloat("ledgeSpeed") == -1) { movementSpeed = 0; } animator.SetFloat("ledgeSpeed", Mathf.Lerp(animator.GetFloat("ledgeSpeed"), 0, ((((movingDetectors.moveSpeed / 3) / movingDetectors.burstLength) / ((movingDetectors.moveSpeed * 2) / (3 + movingDetectors.moveSpeed))) * 12) * Time.deltaTime)); } } //animating switching to a ledge on the left side of the player else if (animator.GetFloat("ledgeSpeed") != -2 && !switchJumping) { animator.speed = (ledgeSwitchingDetectors.switchJumpSpeed / switchPointDist * 3) / 4; animator.CrossFade("LedgeMovement", 0f, -1, 0f); animator.SetFloat("ledgeSpeed", -2); } } else { animator.speed = 1; if (!switching) { animator.SetFloat("ledgeSpeed", 0); } } } if (grabbedOn && !pullingUp && !turnBack && !animator.GetCurrentAnimatorStateInfo(0).IsName("LedgeMovement")) { animator.SetFloat("ledgeSpeed", 0); animator.CrossFade("LedgeMovement", 0f, -1, 0f); } } else { animator.SetBool("onLedge", false); } if (!turnBack && !grabbedOn && !pullingUp) { turnedBackToLedge = false; } //animating climbing over a ledge if (pullingUp) { if (animator.GetFloat("ledgeState") != 3 || !animator.GetCurrentAnimatorStateInfo(0).IsName("LedgeMovement")) { if (!animatePullingUp) { if (grabbedOnLastUpdate) { animator.speed = Mathf.Abs((climbingDetectors.pullUpSpeed / 4) * (onLedgeHeight2 / 19 + 1)); } else { animator.speed = climbingDetectors.pullUpSpeed / 4; } animator.SetFloat("ledgeState", 3); animator.CrossFade("LedgeMovement", 0f, -1, 0f); animatePullingUp = true; } } } else if (animatePullingUp) { animator.speed = 1; animatePullingUp = false; } //animating jumping off of a ledge after walking off if (!animator.GetCurrentAnimatorStateInfo(0).IsName("LedgeJump") && inAirFromJumpingOffLedge && animateLedgeJump) { animator.CrossFade("LedgeJump", 0f, -1, 0f); animateLedgeJump = false; } if (!inAirFromJumpingOffLedge || currentStatesOfVariables.grounded) { animateLedgeJump = true; } if (!pullingUp && !turnBack && !back2) { if (animator.GetBool("onLedge")) { animator.SetFloat("ledgeState", 0); } if (animator.GetCurrentAnimatorStateInfo(0).IsName("LedgeMovement") && animator.GetFloat("ledgeState") != 3 && !grabbedOn) { animator.SetBool("onLedge", false); animator.CrossFade("Movement", 0f, -1, 0f); } } } if (grabbedOn) { grabbedOnLastUpdate = true; } else if (!pullingUp) { grabbedOnLastUpdate = false; } //ledge switching SwitchingLedges(); }
public void Start() { _guiCanvas = GuiCanvas.Instance; _talkingUi = _guiCanvas.TalkingUi; _animator = GetComponentInChildren<Animator>(); _birdProps = BirdPropsService.Instance.GetBirdPropsById(TextId); if (_birdProps != null) { if (_birdProps.AnimatorController != null) { _animator.runtimeAnimatorController = _birdProps.AnimatorController; } _animator.CrossFade(_birdProps.DefaultAnim, 0f); } else { _birdProps = new BirdProps("Idle", true, null); } QMark = transform.FindChild("?").gameObject; QMark.SetActive(false); Directions = DirectionService.Instance.GetDirectionsById(TextId); _animator.CrossFade(_birdProps.DefaultAnim, 0f); _animator.transform.localScale = _animator.transform.localScale.SetX(_birdProps.FaceLeft ? 1 : -1); if (State.Instance.LevelEntrance == LevelEntrance.BeachRival && TextId == "Rival") { var lossDialog = new List<Direction> { new Line("Winson \"Collecto\"", "Woof. Erm, Chirp. Not the best dancing I've seen."), new Line("Winson \"Collecto\"", "We can go again any time. You may need to practice.") }; var perfectDialog = new List<Direction> { new Line("Winson \"Collecto\"", "Wow. Just wow. I am very impressed."), new Line("Winson \"Collecto\"", "So, about your prize. It's the most prized and valuable thing to my name."), new Line("Winson \"Collecto\"", "It's... my respect. You have my respect. Good job guy."), new Line("Winson \"Collecto\"", "We can go again any time.") }; var okDialog = new List<Direction> { new Line("Winson \"Collecto\"", "Pretty good. Not perfect, but pretty good."), new Line("Winson \"Collecto\"", "You're an ok bird."), new Line("Winson \"Collecto\"", "We can go again any time, if you'd like.") }; Directions = new List<Direction> { new Line("Winson \"Collecto\"", "Wow. Just wow. I am very impressed."), new Line("Winson \"Collecto\"", "So, about your prize. It's the most prized and valuable thing to my name."), new Line("Winson \"Collecto\"", "It's... my respect. You have my respect. Good job guy."), new Line("Winson \"Collecto\"", "We can go again any time.") }; if (State.Instance.FailedBeats <= 5 && State.Instance.FailedBeats > 2) { Directions = okDialog; } else if (State.Instance.FailedBeats <= 2) { Directions = perfectDialog; } else { Directions = lossDialog; } _animator.CrossFade("Talk", 0f); StartCoroutine(StartSequence(() => { Directions = DirectionService.Instance.GetDirectionsById(TextId); FindObjectOfType<Control>().Disabled = false; _animator.CrossFade("Idle", 0f); })); } }
void FastForwardAnimator(Animator animator, float second, float crossfade) { for (var layer = 0; layer < animator.layerCount; layer++) { var info = animator.GetCurrentAnimatorStateInfo(layer); if (crossfade > 0.0f) animator.CrossFade(info.nameHash, crossfade / info.length, layer, info.normalizedTime + second / info.length); else animator.Play(info.nameHash, layer, info.normalizedTime + second / info.length); } }
void testeDeVida(Transform Y,Animator Z) { float W = Y.GetComponent<umCriature> ().criature ().cAtributos [0].Corrente; if(W<=0) { Z.CrossFade("cair",0); } }
void Start() { animator = GetComponent<Animator>(); eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>(); continueButton = GameObject.Find("Panel/Main/ContinueButton").GetComponent<Button>(); continueButton.onClick.AddListener(ContinueGame); newGameButton = GameObject.Find("Panel/Main/NewGameButton").GetComponent<Button>(); newGameButton.onClick.AddListener(NewGame); optionsButton = GameObject.Find("Panel/Main/OptionsButton").GetComponent<Button>(); optionsButton.onClick.AddListener(EnterOptions); exitButton = GameObject.Find("Panel/Main/ExitButton").GetComponent<Button>(); exitButton.onClick.AddListener(Exit); backButton = GameObject.Find("Panel/Options/BackButton").GetComponent<Button>(); backButton.onClick.AddListener(LeaveOptions); yesButton = GameObject.Find("Panel/Override/YesButton").GetComponent<Button>(); yesButton.onClick.AddListener(ConfirmOverride); noButton = GameObject.Find("Panel/Override/NoButton").GetComponent<Button>(); noButton.onClick.AddListener(CancelOverride); musicVolumeSlider = GameObject.Find("Panel/Options/MusicSlider").GetComponent<Slider>(); musicVolumeSlider.onValueChanged.AddListener(Utils.ChangeMusicVolume); sfxVolumeSlider = GameObject.Find("Panel/Options/SFXSlider").GetComponent<Slider>(); sfxVolumeSlider.onValueChanged.AddListener(Utils.ChangeSfxVolume); granny = GameObject.Find("Granny").GetComponent<PlayerController>(); PlayerController.IsAttacking = false; //quick fix levelEntries = GameObject.FindObjectsOfType<LevelEntry>(); if (GameProgress.Instance.Level == 0) { continueButton.interactable = false; } if (ShowLevelSelection) { animator.SetBool("LevelSelect", true); animator.CrossFade("MainLevelSelect", 0.0f); granny.IsControllable = true; } else { granny.IsControllable = false; selectLeftButton(); } }
void Awake(){ panda_audio = this.gameObject.AddComponent<AudioSource>(); panda_audio.playOnAwake = false; panda_audio.loop = false; enu_audio = this.gameObject.AddComponent<AudioSource>(); enu_audio.playOnAwake = false; enu_audio.loop = false; // player = GetComponentInParent<Animator>(); last_trap_obj = null; transform = GetComponentInParent<Transform> (); player = transform.Find("panda").gameObject.GetComponentInParent<Animator>(); left_check = transform.Find(LEFT_CHECK); right_check = transform.Find(RIGHT_CHECK); up_check = transform.Find(UP_CHECK); down_check = transform.Find(DOWN_CHECK); if (stand_direction == 1) { player.CrossFade ("down", 0); } else if (stand_direction == 2) { player.CrossFade ("stand_",0); }else if(stand_direction == 3){ player.CrossFade ("left_stand_",0); }else if(stand_direction == 4){ player.CrossFade ("right_stand_",0); } }