public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //This is where combatanimation gets turned of after played wanted amount of time. //Portrett is player animation if (animator.name == "Portrett") { if (stateInfo.normalizedTime > 1 && !animator.IsInTransition (layerIndex)) { if (animator.GetBool ("isHappyMainCharacter") == true) { animator.SetBool ("isHappyMainCharacter", false);//Length 2 sec } if (animator.GetBool ("isAngryMainCharacter") == true) { animator.SetBool ("isAngryMainCharacter", false);//Length 2.45 sec } } } //This is boss animation else if (animator.name == "Portrett2_boss") { if (stateInfo.normalizedTime > 2 && !animator.IsInTransition (layerIndex)) { if (animator.GetBool ("isHappyBoss") == true) { animator.SetBool ("isHappyBoss", false);//Length 1 sec } if (animator.GetBool ("isAngryBoss") == true) { animator.SetBool ("isAngryBoss", false);//Length 1.2 sec } } } //This is enemy animation else if (animator.name == "Portrett2_marine") { if (stateInfo.normalizedTime > 2 && !animator.IsInTransition (layerIndex)) { if (animator.GetBool ("isHappyMarine") == true) { animator.SetBool ("isHappyMarine", false);//Length 1.2 sec } if (animator.GetBool ("isAngryMarine") == true) { animator.SetBool ("isAngryMarine", false);//Length 1.2 sec } } } }
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { // We own this player: send the others our data stream.SendNext(transform.position); stream.SendNext(transform.rotation); anim = GetComponent< Animator >(); stream.SendNext(anim.GetFloat("Speed")); stream.SendNext(anim.GetFloat("Direction")); stream.SendNext(anim.GetBool("Punch_L")); stream.SendNext(anim.GetBool("LowKick")); stream.SendNext(anim.GetBool("HiKick")); stream.SendNext(anim.GetBool("Shoryuken")); myThirdPersonController myC = GetComponent<myThirdPersonController>(); stream.SendNext((int)myC._characterState); } else { // Network player, receive data this.correctPlayerPos = (Vector3)stream.ReceiveNext(); this.correctPlayerRot = (Quaternion)stream.ReceiveNext(); anim = GetComponent< Animator >(); anim.SetFloat("Speed",(float)stream.ReceiveNext()); anim.SetFloat("Direction",(float)stream.ReceiveNext()); anim.SetBool("Punch_L",(bool)stream.ReceiveNext()); anim.SetBool("LowKick",(bool)stream.ReceiveNext()); anim.SetBool("HiKick", (bool)stream.ReceiveNext()); anim.SetBool("Shoryuken", (bool)stream.ReceiveNext()); myThirdPersonController myC = GetComponent<myThirdPersonController>(); myC._characterState = (CharacterState)stream.ReceiveNext(); } }
public static bool TriggerExists(this UnityEngine.Animator animator, string triggerName) { if (!animator) { return(false); } animator.logWarnings = false; bool origVal = animator.GetBool(triggerName); animator.SetBool(triggerName, true); if (!animator.GetBool(triggerName)) { return(false); } animator.SetBool(triggerName, false); if (animator.GetBool(triggerName)) { return(false); } animator.SetBool(triggerName, origVal); return(true); }
// 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); }
// 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) { if (animator.GetBool("death")) { animator.SetBool("died", true); animator.SetBool("death", false); } }
protected override bool ConditionToChangeOn(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (animator.GetBool(GroundVariableName) && !animator.IsInTransition(layerIndex)) { return ChangeOnGround; } else { return ChangeOnAir; } }
// 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) { if(animator.GetBool("Grounded")) { UnityEngine.Random rnd = new UnityEngine.Random(); //animator.GetComponentInParent<Rigidbody>().AddForce(new Vector3(rnd.RandomRange(-1.0f, 1.0f), rnd.RandomRange(-20.0f, 20.0f), rnd.RandomRange(-1.0f, 1.0f)); animator.GetComponentInParent<Rigidbody>().AddForce(new Vector3(0f, 20f, 0f)); animator.SetBool("Grounded", false); } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { bool OnGround = animator.GetBool("OnGround"); float jumpVal = animator.GetFloat("Jump"); if(OnGround && jumpVal > -2) { //if(soundBank != null) // soundBank.PlaySound("Land"); } }
private float GetXAxisForce(Animator animator) { float xForce =50f; if(animator.GetBool(PLATFORM_PARAMETER)) { xForce = 0f; } if (animator.GetBool(HOLE_PARAMATER)) { xForce = 150f; Vector2 newVelocity = mBody.velocity; newVelocity.x = Mathf.Sign(animator.GetFloat("Speed")) * 7f; mBody.velocity = newVelocity; } xForce *= Mathf.Sign(animator.GetFloat("Speed")); return xForce; }
// 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) { if (castingTime >= 0) { //Does not finish casting, hero is hit if (animator.GetBool(isDelayedHash)) { castingTime += 0.5f; animator.SetFloat(castingTimeHash, castingTime); return; } if (animator.GetBool(isInterruptedHash)) { castingTime = 0.0f - float.Epsilon; animator.SetFloat(castingTimeHash, castingTime); return; } } }
public void ToggleVisible(Animator anim) { if (anim.GetBool("isDisplayed")) { anim.SetBool("isDisplayed", false); } else { anim.SetBool("isDisplayed", true); } }
// 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 override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animator.gameObject.GetComponent<PressStart>().mode = animator.GetInteger("mode"); poof = animator.gameObject.GetComponentsInChildren<ParticleSystem>(); foreach (var puff in poof) { Debug.Log("Puff"); puff.Play(); } animator.SetBool("flipped", !animator.GetBool("flipped")); //UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject (GameObject.FindGameObjectWithTag ("UI Element")); //anim.SetInteger("mode", menuNumber); }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (_elapsedTime < stateInfo.length + _delayAfterFinish) { _elapsedTime += Time.deltaTime; } else if (!animator.GetBool(CharController.DeadBool)) { animator.SetBool(CharController.DyingBool, false); animator.SetBool(CharController.DeadBool, true); } }
public new void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!animator.GetBool("drawBowBool")) { if (!this.playerEvents) { this.playerEvents = animator.transform.GetComponent<animEventsManager>(); } if (this.playerEvents) { this.playerEvents.enableSpine(); } } }
// Use this for initialization void Start() { characterController = GetComponent<CharacterController>(); game = GameObject.Find("GAME"); gameScript = game.GetComponent<GameScript>(); player = gameScript.Player.gameObject; animator = transform.FindChild("zombi1animated").gameObject.GetComponent<Animator>(); target = player.transform.position; target.y = transform.position.y; animator.SetBool("walking1", Random.Range(0, 2) == 0 ? true : false); Debug.Log("walking1: " + animator.GetBool("walking1")); move = true; }
object GetParameterValue(Animator anim, AnimatorControllerParameterType type, int nameHash) { switch (type) { case AnimatorControllerParameterType.Bool: case AnimatorControllerParameterType.Trigger: return anim.GetBool(nameHash); case AnimatorControllerParameterType.Float: return anim.GetFloat(nameHash); case AnimatorControllerParameterType.Int: return anim.GetInteger(nameHash); default: return null; } }
IEnumerator DisablePanelDeleyed(Animator anim) { bool closedStateReached = false; bool wantToClose = true; while (!closedStateReached && wantToClose) { if (!anim.IsInTransition(0)) closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(k_ClosedStateName); wantToClose = !anim.GetBool(m_OpenParameterId); yield return new WaitForEndOfFrame(); } if (wantToClose) anim.gameObject.SetActive(false); }
public static void CopyParamsFrom(this Animator self, Animator from) { AnimatorControllerData.ControllerData data = AnimatorControllerData.Instance.GetData(from.runtimeAnimatorController.name.GetHashCode()); AnimatorControllerData.Parameter[] parameters = data.Parameters; for (int i = 0; i < parameters.Length; i++) { AnimatorControllerData.Parameter parameter = parameters[i]; switch (parameter.ParamType) { case AnimatorControllerData.ParamType.Bool: self.SetBoolReflected(parameter.Name, from.GetBool(parameter.Name)); break; case AnimatorControllerData.ParamType.Int: self.SetIntegerReflected(parameter.Name, from.GetInteger(parameter.Name)); break; case AnimatorControllerData.ParamType.Float: self.SetFloatReflected(parameter.Name, from.GetFloat(parameter.Name)); break; } } }
// Use this for initialization void Awake() { catTransform = GetComponent<Transform>(); anim = GetComponent<Animator>(); bigCollider = catTransform.FindChild("BigCollider").gameObject; smallCollider = catTransform.FindChild("SmallCollider").gameObject; polyNav = GetComponent<PolyNavAgent>(); polyNav.maxSpeed = catSpeed; changeColliders(anim.GetBool("Sleeping")); if (Application.loadedLevel == 2) { isLevel1 = true; } if (DEBUG) Debug.Log("Cat's current position is: " + catTransform.position.x + ", " + catTransform.position.y); }
private IEnumerator DisablePanelDeleyed(Animator anim) { bool closedStateReached = false; // Closed 상태로 완전히 전이되었는가? bool wantToClose = true; // 코루틴 도중에 anim 값바뀜 체크? while (!closedStateReached && wantToClose) { if (!anim.IsInTransition(0)) { closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(_closedStateName); } wantToClose = !anim.GetBool(_openParameterId); yield return new WaitForEndOfFrame(); } if (wantToClose) { anim.gameObject.SetActive(false); } }
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //called on the last frame of a transition to another state. //trigger other to speak self.monologuebox.SetActive(false); if (animator.GetBool("speak")) { self.Interrupt(); } else { if (keep_going) { if (self.other) self.other.Speak(); else self.Speak(); } } }
void Start() { //initialize persistentData... persistentData = GameObject.FindGameObjectWithTag (Tags.mainCamera).GetComponent<PersistentData> (); //initialize player head animator... playerHeadAnimator = GetComponent<Animator> (); currentValue = playerHeadAnimator.GetBool ("helmetEquipped"); switch (persistentData.playerHelmetEquipped){ //if persistentData helmet state is set to 0 ("default") case 0: //then set the helmet state based on the starting scene state... if(startSceneWithHelmetEquipped && !currentValue){ playerHeadAnimator.SetTrigger ("equipHelmetNoEffects"); } else if(!startSceneWithHelmetEquipped && currentValue){ playerHeadAnimator.SetTrigger ("removeHelmet"); } break; //if persistentData helmet state is set to 1 ("not equipped"); case 1: if(currentValue){ playerHeadAnimator.SetTrigger ("removeHelmet"); } break; //if persistentData helmet state is set to 2 ("equipped"); case 2: if(!currentValue){ playerHeadAnimator.SetTrigger ("equipHelmetNoEffects"); } break; default: break; } }
private object GetParameterValue(int i, AnimatorControllerParameterType type, Animator animator) { switch (type) { case AnimatorControllerParameterType.Float: return animator.GetFloat(i); case AnimatorControllerParameterType.Int: return animator.GetInteger(i); case AnimatorControllerParameterType.Bool: return animator.GetBool(i); case AnimatorControllerParameterType.Trigger: return animator.GetBool(i); default: return null; } }
//Either auto attack on distance, or aim. // Use this for initialization void Start() { parentObject = transform.parent.gameObject; anim = transform.parent.gameObject.GetComponent<Animator> (); currentDirectionIsRight = anim.GetBool ("facingRight"); }
//Coroutine that will detect when the Closing animation is finished and it will deactivate the //hierarchy. IEnumerator DisablePanelDeleyed(Animator anim) { bool closedStateReached = false; bool wantToClose = true; while (!closedStateReached && wantToClose) { if (!anim.IsInTransition(0)) closedStateReached = anim.GetCurrentAnimatorStateInfo(0).IsName(k_ClosedStateName); wantToClose = !anim.GetBool(m_OpenParameterId); yield return new WaitForEndOfFrame(); } if (wantToClose) { RectTransform rect = anim.gameObject.GetComponent<RectTransform>(); rect.SetParent(PoolRoot); rect.anchoredPosition = new Vector2(0f, 0f); anim.gameObject.SetActive(false); } }
public override void OnEnter() { animator = ownerDefault.GetComponent <UnityEngine.Animator> (); owner.SetBool(store, animator.GetBool(hash)); Finish(); }
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 bool Test(Animator animator) { if (this.conditions.Count == 0) { return true; } for (int i = 0; i < this.conditions.Count; i++) { EventConditionEntry eventConditionEntry = this.conditions[i]; if (!string.IsNullOrEmpty(eventConditionEntry.conditionParam)) { switch (eventConditionEntry.conditionParamType) { case EventConditionParamTypes.Int: { int integer = animator.GetInteger(eventConditionEntry.conditionParam); switch (eventConditionEntry.conditionMode) { case EventConditionModes.Equal: if (integer != eventConditionEntry.intValue) { return false; } break; case EventConditionModes.NotEqual: if (integer == eventConditionEntry.intValue) { return false; } break; case EventConditionModes.GreaterThan: if (integer <= eventConditionEntry.intValue) { return false; } break; case EventConditionModes.LessThan: if (integer >= eventConditionEntry.intValue) { return false; } break; case EventConditionModes.GreaterEqualThan: if (integer < eventConditionEntry.intValue) { return false; } break; case EventConditionModes.LessEqualThan: if (integer > eventConditionEntry.intValue) { return false; } break; } break; } case EventConditionParamTypes.Float: { float @float = animator.GetFloat(eventConditionEntry.conditionParam); EventConditionModes conditionMode = eventConditionEntry.conditionMode; if (conditionMode != EventConditionModes.GreaterThan) { if (conditionMode == EventConditionModes.LessThan) { if (@float >= eventConditionEntry.floatValue) { return false; } } } else if (@float <= eventConditionEntry.floatValue) { return false; } break; } case EventConditionParamTypes.Boolean: { bool @bool = animator.GetBool(eventConditionEntry.conditionParam); if (@bool != eventConditionEntry.boolValue) { return false; } break; } } } } return true; }
void Update() { // Debug.Log("Current: " + current.tag); if(god.CharacterCount == 0) return; currentAnim = current.GetComponent<Animator>(); if(currentAnim.GetBool("Grounded")) lastSafeLocation = current.transform.position; if (Input.GetKeyDown (KeyCode.F1) && currentCharacter != 1 && god.isAlive (0)) { Debug.Log("Changing character into: Character 0"); characters[0].CharacterGameObject.transform.position = current.transform.position; current.SetActive( false); current = characters[0].CharacterGameObject; current.SetActive(true); camera.SwitchPlayer(current); currentCharacter = 1; } else if(Input.GetKeyDown (KeyCode.F1) && currentCharacter != 1 && !god.isAlive (0)) Debug.Log("Target Character is not alive."); if (Input.GetKeyDown (KeyCode.F2) && currentCharacter != 2 && god.isAlive (1)) { Debug.Log("Changing character into: Character 1"); characters[1].CharacterGameObject.transform.position = current.transform.position; current.SetActive( false); current = characters[1].CharacterGameObject; current.SetActive(true); camera.SwitchPlayer(current); currentCharacter = 2; } else if(Input.GetKeyDown (KeyCode.F2) && currentCharacter != 2 && !god.isAlive (1)) Debug.Log("Target Character is not alive."); if (Input.GetKeyDown (KeyCode.F3) && currentCharacter != 3 && god.isAlive (2)) { Debug.Log("Changing character into: Character 2"); characters[2].CharacterGameObject.transform.position = current.transform.position; current.SetActive( false); current = characters[2].CharacterGameObject; current.SetActive(true); camera.SwitchPlayer(current); currentCharacter = 3; } else if(Input.GetKeyDown (KeyCode.F3) && currentCharacter != 3 && !god.isAlive (2)) Debug.Log("Target Character is not alive."); }
public override void OnEnter () { animator = ownerDefault.GetComponent<UnityEngine.Animator> (); owner.SetBool (store, animator.GetBool (hash)); Finish (); }
// While we are being thrown. Using this to see if our grabber gets hurt so that we // can break out still. IEnumerator BeingThrown(Transform grabMount, Animator grabberAnim) { while (anim.GetInteger("HurtOther") != 5) // While not thrown { if (grabberAnim.GetBool("IsHurt")) BrokeFromGrab(grabMount); yield return new WaitForSeconds(0.0001f); } StopCoroutine("BeingThrown"); }
void Start() { newPosition = transform.position; anim = GetComponent<Animator>(); Input.simulateMouseWithTouches = true; if (PlayerPrefs.GetInt("isAlliance") == 1) { anim.SetBool("isAlliance", true); } else { anim.SetBool("isAlliance", false); } if(anim.GetBool("isAlliance")==true) { transform.position = allianceSpawnPoint.transform.position; } else { transform.position = federationSpawnPoint.transform.position; } }