// Use this for initialization void Start () { ani = this.GetComponent<Animator> (); dirX = ani.GetFloat("dirX"); dirY = ani.GetFloat("dirY"); ani.SetBool("running", false); }
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(); } }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { m_PlayerController = animator.gameObject.GetComponent<PlayerController>(); m_IKTransitionTime = animator.GetFloat("IKTransitionTime"); m_MoveTime = animator.GetFloat("MoveTime"); m_MoveTimer = 0.0f; }
// Use this for initialization void Start () { rb = GetComponent<Rigidbody2D>(); playerAnim = GameObject.FindGameObjectWithTag("Player").GetComponent<Animator>(); anim = GetComponent<Animator>(); target = new Vector3(playerAnim.GetFloat("lastX"), playerAnim.GetFloat("lastY"), 0f); rb.velocity = target.normalized * moveSpd; Debug.Log(target); }
public void Start() { // Get the values of the parameters: string animatorParameter = GetParameter(0); animatorParameterHash = Animator.StringToHash(animatorParameter); targetValue = GetParameterAsFloat(1, 1); subject = GetSubject(2); duration = GetParameterAsFloat(3, 0); if (DialogueDebug.LogInfo) Debug.Log(string.Format("{0}: Sequencer: AnimatorFloat({1}, {2}, {3}, {4})", new System.Object[] { DialogueDebug.Prefix, animatorParameter, targetValue, subject, duration })); // Check the parameters: if (subject == null) { if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AnimatorFloat(): subject '{1}' wasn't found.", new System.Object[] { DialogueDebug.Prefix, GetParameter(2) })); Stop(); } else { animator = subject.GetComponentInChildren<Animator>(); if (animator == null) { if (DialogueDebug.LogWarnings) Debug.LogWarning(string.Format("{0}: Sequencer: AnimatorFloat(): no Animator found on '{1}'.", new System.Object[] { DialogueDebug.Prefix, subject.name })); Stop(); } else if (duration < SmoothMoveCutoff) { Stop(); } else { // Set up the lerp: startTime = DialogueTime.time; endTime = startTime + duration; originalValue = animator.GetFloat(animatorParameterHash); } } }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex) { float lCurrentSpeedFactor = animator.GetFloat("speed"); float lTime = animatorStateInfo.normalizedTime - Mathf.Floor(animatorStateInfo.normalizedTime); float lBlendedTime = 0.5f - 0.25f * lCurrentSpeedFactor; FootPlacementData[] lFeet = animator.GetComponents<FootPlacementData>(); FootPlacementData lFoot; //First foot setup start if(!lFeet[0].IsLeftFoot) { lFoot = lFeet[0]; } else { lFoot = lFeet[1]; } //Setting up transition time lFoot.mTransitionTime = 0.15f - (0.1f * lCurrentSpeedFactor); //Setting up raycast extra ray dist if(lTime < lBlendedTime) { lFoot.mExtraRayDistanceCheck = 0.7f; } else { lFoot.mExtraRayDistanceCheck = -0.2f; } //First foot setup end //Second foot setup start if(lFeet[0].IsLeftFoot) { lFoot = lFeet[0]; } else { lFoot = lFeet[1]; } //Setting up transition time lFoot.mTransitionTime = 0.15f - (0.1f * lCurrentSpeedFactor); //Setting up raycast extra ray dist if(lTime > 0.5 && lTime < 0.5f + lBlendedTime) { lFoot.mExtraRayDistanceCheck = 0.7f; } else { lFoot.mExtraRayDistanceCheck = -0.2f; } //Second foot setup end }
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { m_PlayerController = animator.gameObject.GetComponent<PlayerController>(); m_MoveTimer = 0.0f; m_IKTransitionTime = animator.GetFloat("IKTransitionTime"); m_MoveTime = animator.GetFloat("MoveTime"); m_MoveDistance = animator.GetFloat("MoveDistance"); Vector3 newPosition = animator.transform.position; newPosition.x -= m_MoveDistance; Hashtable hash = iTween.Hash("position", newPosition, "time", m_MoveTime, "easetype", iTween.EaseType.easeOutElastic); iTween.MoveTo(animator.gameObject, hash); m_IKSwitched = false; }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { float jumpLeg = animator.GetFloat("JumpLeg"); if((rightLeg && jumpLeg >= .7f) || (!rightLeg && jumpLeg <= -.7f)) { rightLeg = !rightLeg; if(soundBank != null) soundBank.PlaySound("FootStep"); } }
// 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) { this._animator = animator; this._stateInfo = stateInfo; _baseMoveMultiplier = _animator.GetFloat("moveMultiplier"); _thisBattleCharacter = animator.GetComponent<AbstractBattleCharacter>(); _thisBattleCharacter.StartCoroutine(RotateAndMoveTowards(_thisBattleCharacter.gameObject)); }
public static void PartiallyDestroy(Transform obj, Animator bulletAnim) { float input_x = bulletAnim.GetFloat("input_x"); float input_y = bulletAnim.GetFloat("input_y"); obj.NotNull((t) => { Animator wallAnim = t.GetComponent<Animator>(); float curr = wallAnim.GetFloat("left_numpad"); // The tyniest piece of wall left if (curr.IsIn(1, 3, 7, 9)) { Destroy(t.gameObject); } // Vertical shot else if (input_x == 0) { if (curr.IsIn(2, 8)) { Destroy(t.gameObject); } else if (curr.IsIn(4, 5, 6)) { wallAnim.SetFloat("left_numpad", curr + input_y * 3); } } // Horizontal shot else if (input_y == 0) { if (curr.IsIn(4, 6)) { Destroy(t.gameObject); } else if (curr.IsIn(2, 5, 8)) { wallAnim.SetFloat("left_numpad", curr + input_x); } } }); }
private void PartiallyDestroy(Transform obj, Animator bulletAnim) { float input_x = bulletAnim.GetFloat("input_x"); float input_y = bulletAnim.GetFloat("input_y"); obj.NotNull((t) => { Animator wallAnim = t.GetComponent<Animator>(); float curr = wallAnim.GetFloat("left_numpad"); // Strong shot will allways destroy a piece (and maybe two) Destroy(t.gameObject); // Horizontal shot if (input_x == 1 && curr.IsIn(3, 6, 9)) { obj.position += new Vector3(1, 0, 0); BulletWallDestroy.PartiallyDestroy(ts.GetByNameAndCoords ("Wall", obj.position.x, obj.position.y), bulletAnim); } if (input_x == -1 && curr.IsIn(1, 4, 7)) { obj.position += new Vector3(-1, 0, 0); BulletWallDestroy.PartiallyDestroy(ts.GetByNameAndCoords ("Wall", obj.position.x, obj.position.y), bulletAnim); } // Vertical shot if (input_y == 1 && curr.IsIn(7, 8, 9)) { obj.position += new Vector3(0, 1, 0); BulletWallDestroy.PartiallyDestroy(ts.GetByNameAndCoords ("Wall", obj.position.x, obj.position.y), bulletAnim); } if (input_y == -1 && curr.IsIn(1, 2, 3)) { obj.position += new Vector3(0, -1, 0); BulletWallDestroy.PartiallyDestroy(ts.GetByNameAndCoords ("Wall", obj.position.x, obj.position.y), bulletAnim); } }); }
// 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; }
public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { float speed = animator.GetFloat(SPEED_PARAMATER); if (speed != 0) { Move(speed); } CheckFlipping(speed); }
// OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here public override void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // play talk and idle sound talkSound.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(animator.gameObject.transform)); idleSound.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(animator.gameObject.transform)); if ((animator.GetFloat("Speed") != 1) && (animator.GetFloat("vSpeed") == 0)) { talkSound.setVolume(1); idleSound.setVolume(1); } else { talkSound.setVolume(0); idleSound.setVolume(0); } // play roll sound according to speed parameter rollSound.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(animator.gameObject.transform)); rollSound.setParameterValue("speed", animator.GetFloat("Speed")); // play leaves sound leavesSound.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(animator.gameObject.transform)); leavesSound.setParameterValue("speed", animator.GetFloat("Speed")); // play jump sound (oneshot) if ((animator.GetFloat("vSpeed") > 11) && (playOnceJump == true)) { FMODUnity.RuntimeManager.PlayOneShot("event:/robo_jump", animator.gameObject.transform.position); playOnceJump = false; playOnceLand = true; leavesSound.setVolume(0); } // play land sound (oneshot) if ((animator.GetFloat("vSpeed") < -5) && (playOnceLand == true)) { FMODUnity.RuntimeManager.PlayOneShot("event:/robo_land", animator.gameObject.transform.position); playOnceLand = false; playOnceJump = true; leavesSound.setVolume(1); } }
// 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 public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (stateInfo.normalizedTime > WhenDestroy && !animator.IsInTransition(layerIndex)) { if (DependsOnSpeed) { if (animator.GetFloat(SpeedVariableName) == Speed) { Destroy(animator.gameObject); } } else { Destroy(animator.gameObject); } } }
// 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) { //Get castingTime castingTime = animator.GetFloat(castingTimeHash); //TODO:castTime should get from current skill float skillCastTime = 1.2f; if (castingTime < 0.0f || castingTime > skillCastTime) { castingTime = skillCastTime; } }
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; } }
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { base.OnStateEnter (animator, stateInfo, layerIndex); if (mBody.velocity.y < 0.01 && mBody.velocity.y > -0.01) { float speed = animator.GetFloat(SPEED_PARAMATER); float xForce = GetXAxisForce(animator); mBody.AddForce(new Vector2 (xForce, m_JumpForce)); } ReinitializeJumpParamater(animator); ReinitializePlateformParamater(animator); ReinitializePHoleParamater(animator); }
// Update is called once per frame void Update() { Vector3 velocity; string str; m_Agent.speed = m_Animator.GetFloat("NAV_SPEED"); //NavMeshAgentの移動速度をAniamtorのParameterから取得する。 #if CHARA_CONTROLLER velocity = m_CController.velocity; #elif NAVMESH velocity = m_Agent.velocity; #else velocity = m_RBody.velocity; #endif str = string.Format("velocity=({0},{1},{2})", velocity.x, velocity.y, velocity.z); Debug.Log(str); }
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; } } }
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(); }
// 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) { stepWidth = animator.GetFloat("stepWidth"); syncronizer = GameObject.Find("AudioManager").GetComponent<BeatSynchronizer>(); }
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; }
// 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) { animator.speed = animator.GetFloat ("WalkSpeed"); }
public override void OnEnter() { animator = ownerDefault.GetComponent <UnityEngine.Animator> (); owner.SetFloat(store, animator.GetFloat(hash)); Finish(); }
// Use this for initialization void Start() { animator = GetComponent<Animator> (); timer = animator.GetFloat ("Eye_Timer"); }
private AnimatorStateInfo layer2CurrentState; // a reference to the current state of the animator, used for layer 2 #endregion Fields #region Methods void FixedUpdate() { anim = GetComponent<Animator>(); float h = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis float v = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis anim.SetFloat("Speed", v); // set our animator's float parameter 'Speed' equal to the vertical input axis anim.SetFloat("Direction", h); // set our animator's float parameter 'Direction' equal to the horizontal input axis anim.speed = animSpeed; // set the speed of our animator to the public variable 'animSpeed' anim.SetLookAtWeight(lookWeight); // set the Look At Weight - amount to use look at IK vs using the head's animation currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // set our currentState variable to the current state of the Base Layer (0) of animation if(anim.layerCount ==2) layer2CurrentState = anim.GetCurrentAnimatorStateInfo(1); // set our layer2CurrentState variable to the current state of the second Layer (1) of animation // LOOK AT ENEMY // if we hold Alt.. if(Input.GetButton("Fire2")) { // ...set a position to look at with the head, and use Lerp to smooth the look weight from animation to IK (see line 54) anim.SetLookAtPosition(enemy.position); lookWeight = Mathf.Lerp(lookWeight,1f,Time.deltaTime*lookSmoother); } // else, return to using animation for the head by lerping back to 0 for look at weight else { lookWeight = Mathf.Lerp(lookWeight,0f,Time.deltaTime*lookSmoother); } // STANDARD JUMPING // if we are currently in a state called Locomotion (see line 25), then allow Jump input (Space) to set the Jump bool parameter in the Animator to true /*if (currentBaseState.nameHash == locoState) {*/ if(Input.GetButtonDown("Jump")) { anim.SetBool("Jump", true); } //} // if we are in the jumping state... else if(currentBaseState.nameHash == jumpState) { // ..and not still in transition.. if(!anim.IsInTransition(0)) { /*if(useCurves) // ..set the collider height to a float curve in the clip called ColliderHeight col.height = anim.GetFloat("ColliderHeight");*/ // reset the Jump bool so we can jump again, and so that the state does not loop anim.SetBool("Jump", false); } // Raycast down from the center of the character.. Ray ray = new Ray(transform.position + Vector3.up, -Vector3.up); RaycastHit hitInfo = new RaycastHit(); if (Physics.Raycast(ray, out hitInfo)) { // ..if distance to the ground is more than 1.75, use Match Target if (hitInfo.distance > 1.75f) { // MatchTarget allows us to take over animation and smoothly transition our character towards a location - the hit point from the ray. // Here we're telling the Root of the character to only be influenced on the Y axis (MatchTargetWeightMask) and only occur between 0.35 and 0.5 // of the timeline of our animation clip anim.MatchTarget(hitInfo.point, Quaternion.identity, AvatarTarget.Root, new MatchTargetWeightMask(new Vector3(0, 1, 0), 0), 0.35f, 0.5f); } } } // JUMP DOWN AND ROLL // if we are jumping down, set our Collider's Y position to the float curve from the animation clip - // this is a slight lowering so that the collider hits the floor as the character extends his legs else if (currentBaseState.nameHash == jumpDownState) { col.center = new Vector3(0, anim.GetFloat("ColliderY"), 0); } // if we are falling, set our Grounded boolean to true when our character's root // position is less that 0.6, this allows us to transition from fall into roll and run // we then set the Collider's Height equal to the float curve from the animation clip else if (currentBaseState.nameHash == fallState) { col.height = anim.GetFloat("ColliderHeight"); } // if we are in the roll state and not in transition, set Collider Height to the float curve from the animation clip // this ensures we are in a short spherical capsule height during the roll, so we can smash through the lower // boxes, and then extends the collider as we come out of the roll // we also moderate the Y position of the collider using another of these curves on line 128 else if (currentBaseState.nameHash == rollState) { if(!anim.IsInTransition(0)) { if(useCurves) col.height = anim.GetFloat("ColliderHeight"); col.center = new Vector3(0, anim.GetFloat("ColliderY"), 0); } } // IDLE /* // check if we are at idle, if so, let us Wave! else if (currentBaseState.nameHash == idleState) { if(Input.GetButtonUp("Jump")) { anim.SetBool("Wave", true); } } // if we enter the waving state, reset the bool to let us wave again in future if(layer2CurrentState.nameHash == waveState) { anim.SetBool("Wave", false); } */ }
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; } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { float CD = animator.GetFloat("CD"); CD -= Time.deltaTime; animator.SetFloat("CD", CD); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { animator.SetFloat( "time", animator.GetFloat("time") + Time.deltaTime ); }
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { float x = animator.GetFloat(MovX); float y = animator.GetFloat(MovY); if (Mathf.Abs(x) >= NormalThreshold || Mathf.Abs(y) >= NormalThreshold) { Vector2 normal = new Vector2(x, y); normal.Normalize(); animator.SetFloat(NormalX, normal.x); animator.SetFloat(NormalY, normal.y); } }