public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        base.OnStateUpdate(animator, stateInfo, layerIndex);

        if (Input.GetKeyDown(KeyCode.K))
        {
            if (stateInfo.IsName("PowerAttack.powerattack_1") && stateInfo.normalizedTime > 0.35f)
            {
                animator.CrossFade("powerattack_2", 0);
            }

            else if (stateInfo.IsName("PowerAttack.powerattack_2") && stateInfo.normalizedTime > 0.35f)
            {
                animator.CrossFade("powerattack_3", 0);
            }

            else if (stateInfo.IsName("PowerAttack.powerattack_3") && stateInfo.normalizedTime > 0.35f)
            {
                animator.CrossFade("powerattack_4", 0);
            }

            else if (stateInfo.IsName("PowerAttack.powerattack_4") && stateInfo.normalizedTime > 0.35f)
            {
                animator.CrossFade("powerattack_5", 0);
            }
        }
    }
Esempio n. 2
0
	void Awake(){

        audio = this.gameObject.AddComponent<AudioSource>();
        audio.playOnAwake = false;
        audio.loop = false;

		my_transform = this.gameObject.GetComponent<Transform> ();
		move_enemy = my_transform.Find ("ob");

		player = move_enemy.Find("attact_enemy").gameObject.GetComponent<Animator>();
        bar = this.gameObject.transform.Find("barrel").GetComponent<BoxCollider2D>();
        
		
		
		if (stand_direction == 1) {
			player.CrossFade ("stand_", 0);
		} else if (stand_direction == 2) {
			player.CrossFade ("down",0);
		}else if (stand_direction == 3) {
			player.CrossFade ("left_stand",0);
		}else if (stand_direction == 4) {
			player.CrossFade ("right_stand",0);
		}

		
	}
	void Awake(){
        audio = this.gameObject.AddComponent<AudioSource>();
        audio.playOnAwake = false;
        audio.loop = false;
		my_transform = this.gameObject.GetComponent<Transform> ();
		normal_enymy = my_transform.Find ("normal_enymy");
		player = my_transform.Find ("normal_enymy").gameObject.GetComponent<Animator> ();

		up_check = my_transform.Find ("up_check");
		down_check = my_transform.Find ("down_check");
		left_check = my_transform.Find ("left_check");
		right_check = my_transform.Find ("right_check");


		if (stand_direction == 1) {
			player.CrossFade ("stand_", 0);
		} else if (stand_direction == 2) {
			player.CrossFade ("down",0);
		}else if (stand_direction == 3) {
			player.CrossFade ("left_stand",0);
		}else if (stand_direction == 4) {
			player.CrossFade ("right_stand",0);
		}
		compress ();

	}
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //
    //}
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    //}
    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        var currentDirection = (Direction)animator.GetInteger("FaceDirection");

        if (animator.GetBool("MeleeAttackBool"))
        {
          animator.SetBool("MeleeAttackBool", false);
          switch (currentDirection)
          {
        case Direction.Up:
          animator.CrossFade("P_Idle_Up", 0.5f);
          break;
        case Direction.Down:
          animator.CrossFade("P_Idle_Down", 0.5f);
          break;
        case Direction.Left:
          animator.CrossFade("P_Idle_Left", 0.5f);
          break;
        case Direction.Right:
          animator.CrossFade("P_Idle_Right", 0.5f);
          break;
          }
        }
        ResetAnimationState(animator);
    }
	void Awake(){

        audio = this.gameObject.AddComponent<AudioSource>();
        audio.playOnAwake = false;
        audio.loop = false;


		my_transform = this.gameObject.GetComponent<Transform> ();
		move_enemy = my_transform.Find ("ob");
		if(move_enemy == null){
			Debug.Log("move_enemy is null");
		}
		player = move_enemy.Find("fast_move_enemy").gameObject.GetComponent<Animator>();
		
		up_check = my_transform.Find ("up_check");
		down_check = my_transform.Find ("down_check");
		left_check = my_transform.Find ("left_check");
		right_check = my_transform.Find ("right_check");
		
		
		if (stand_direction == 1) {
			player.CrossFade ("stand", 0);
		} else if (stand_direction == 2) {
			player.CrossFade ("down",0);
		}else if (stand_direction == 3) {
			player.CrossFade ("left_stand",0);
		}else if (stand_direction == 4) {
			player.CrossFade ("right_stand",0);
		}
		
		
	}
	void Awake(){

        audio = this.gameObject.AddComponent<AudioSource>();
        AudioClip clip = Resources.Load<AudioClip>("sound/trap");
        audio.playOnAwake = false;
        audio.loop = false;
        audio.clip = clip;
		change_times = g_d_m.chang_number;
		player = this.gameObject.GetComponent<Animator> ();
		if (direction == 1) {
		
			player.CrossFade ("left_idle",0f);

		} else {
			player.CrossFade ("right_idle",0f);
		}
	}
 public void ResetAnimationState(Animator animator)
 {
     var currentDirection = (Direction)animator.GetInteger("FaceDirection");
     switch (currentDirection)
     {
       case Direction.Up:
     animator.CrossFade("P_Idle_Up", 0.5f);
     break;
       case Direction.Down:
     animator.CrossFade("P_Idle_Down", 0.5f);
     break;
       case Direction.Left:
     animator.CrossFade("P_Idle_Left", 0.5f);
     break;
       case Direction.Right:
     animator.CrossFade("P_Idle_Right", 0.5f);
     break;
     }
 }
Esempio n. 8
0
 // Use this for initialization
 void Start()
 {
     controle = GetComponent<CharacterController> ();
     alturaAtual = transform.position.y;
     alturaDoDano = alturaAtual;
     posicaoInicial = transform.position;
     transform.rotation = Quaternion.LookRotation (-direcaoDoDano);
     cancelaAcao();
     animator = GetComponent<Animator>();
     if(vivo)
         animator.CrossFade("dano1",0);
 }
	void Start ()
	{
		AI.GetComponent<EnemyController> ().enemyState = EnemyController.EnemyState.Walking;
		anim = GetComponent<Animator> ();
		anim.CrossFade ("Walking", 0.1f);
		alreadyRoom = new List<string> ();
		isChangingRoom = false;
		alreadyChangeRoom = false;
		isFromRoomToHall = false;

		//<Viên>
		Direction = 1;

		//<Lâm> 
		//StartCoroutine (whatWayToGo (0.2f));
	}
Esempio n. 10
0
        /// <summary>
        /// Coroutine to play the death animation and disable the actor after a couple of seconds
        /// </summary>
        /// <param name="rDamageValue">Amount of damage to take</param>
        /// <param name="rDamageType">Damage type taken</param>
        /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param>
        /// <param name="rBone">Transform that the damage it... if known</param>
        /// <returns></returns>
        protected virtual IEnumerator InternalDeath(IMessage rMessage)
        {
            ActorController  lActorController  = mActorCore.gameObject.GetComponent <ActorController>();
            MotionController lMotionController = mActorCore.gameObject.GetComponent <MotionController>();

            // Run the death animation if we can
            if (rMessage != null && lMotionController != null)
            {
                // Send the message to the MC to let it activate
                rMessage.ID = CombatMessage.MSG_DEFENDER_KILLED;

                if (DeathMotion.Length > 0)
                {
                    MotionControllerMotion lMotion = lMotionController.GetMotion(DeathMotion);
                    if (lMotion != null)
                    {
                        lMotionController.ActivateMotion(lMotion);
                    }
                    else
                    {
                        int lID = Animator.StringToHash(DeathMotion);
                        if (lID != 0)
                        {
                            Animator lAnimator = mActorCore.gameObject.GetComponent <Animator>();
                            if (lAnimator != null)
                            {
                                try
                                {
                                    lAnimator.CrossFade(DeathMotion, 0.25f, 0);
                                }
                                catch { }
                            }
                        }
                    }
                }
                else
                {
                    lMotionController.SendMessage(rMessage);
                }

                // Trigger the death animation
                yield return(new WaitForSeconds(3.0f));

                // Shut down the MC
                if (_DisableComponents)
                {
                    lMotionController.enabled = false;
                    lMotionController.ActorController.enabled = false;
                }
            }

            // Disable all colliders
            if (_DisableColliders)
            {
                Collider[] lColliders = mActorCore.gameObject.GetComponents <Collider>();
                for (int i = 0; i < lColliders.Length; i++)
                {
                    lColliders[i].enabled = false;
                }
            }

            // Remove the body shapes
            if (_RemoveBodyShapes)
            {
                if (lActorController != null)
                {
                    lActorController.RemoveBodyShapes();
                }
            }

            // Stop the reactor
            Deactivate();
        }
        // Update is called once per frame
        void Update()
        {
            enableRM             = !anim.GetBool("canMove");
            anim.applyRootMotion = enableRM;

            interacting = anim.GetBool("interacting");

            if (lockon == false)
            {
                horizontal = 0;
                vertical   = Mathf.Clamp01(vertical);
            }

            anim.SetBool("lock on", lockon);

            if (enableRM)
            {
                return;
            }

            if (useItem)
            {
                anim.Play("use_item");
                useItem = false;
            }

            if (interacting)
            {
                playAnim = false;
                vertical = Mathf.Clamp(vertical, 0, 0.5f);
            }

            anim.SetBool("two_handed", twoHanded);

            if (playAnim)
            {
                string targetAnim;


                if (!twoHanded)
                {
                    int r = Random.Range(0, oh_attacks.Length);
                    targetAnim = oh_attacks[r];
                    if (vertical > 0.5f)
                    {
                        targetAnim = "oh_attack_3";
                    }
                }
                else
                {
                    int r = Random.Range(0, th_attacks.Length);
                    targetAnim = th_attacks[r];
                }

                vertical = 0;
                anim.CrossFade(targetAnim, 0.2f);
                //anim.SetBool("canMove", false);
                //enableRM = true;
                playAnim = false;
            }

            anim.SetFloat("vertical", vertical);
            anim.SetFloat("horizontal", horizontal);
        }
Esempio n. 12
0
 public void Close()
 {
     open = false;
     animator.CrossFade("closed", 0f);
 }
Esempio n. 13
0
    void Update()
    {
        if (mode == eMode.transition)
        {                                    // b
            rigid.velocity = Vector3.zero;
            anim.speed     = 0;
            roomPos        = transitionPos; // Keeps Dray in place
            if (Time.time < transitionDone)
            {
                return;
            }
            // The following line is only reached if Time.time >= transitionDone
            mode = eMode.idle;
        }

        //————Handle Keyboard Input and manage eDrayModes————
        dirHeld = -1;
        for (int i = 0; i < 4; i++)
        {
            if (Input.GetKey(keys[i]))
            {
                dirHeld = i;
            }
        }

        // Pressing the attack button(s)
        if (Input.GetKeyDown(KeyCode.Z) && Time.time >= timeAtkNext)
        {       // a
            mode        = eMode.attack;
            timeAtkDone = Time.time + attackDuration;
            timeAtkNext = Time.time + attackDelay;
        }

        // Finishing the attack when it's over
        if (Time.time >= timeAtkDone)
        {                                      // b
            mode = eMode.idle;
        }

        // Choosing the proper mode if we're not attacking
        if (mode != eMode.attack)
        {                                          // c
            if (dirHeld == -1)
            {
                mode = eMode.idle;
            }
            else
            {
                facing = dirHeld;                                            // d
                mode   = eMode.move;
            }
        }

        //————Act on the current mode————
        Vector3 vel = Vector3.zero;

        switch (mode)
        {                                                      // e
        case eMode.attack:
            anim.CrossFade("Dray_Attack_" + facing, 0);
            anim.speed = 0;
            break;

        case eMode.idle:
            anim.CrossFade("Dray_Walk_" + facing, 0);
            anim.speed = 0;
            break;

        case eMode.move:
            vel = directions[dirHeld];
            anim.CrossFade("Dray_Walk_" + facing, 0);
            anim.speed = 1;
            break;
        }

        rigid.velocity = vel * speed;
    }
Esempio n. 14
0
    public IEnumerator spawnDummy(getAnimatorParams.DummyParams p)
    {
        Quaternion angle = p.Angle;

        if (BoltNetwork.isClient)
        {
            yield break;
        }
        Vector3 bodyPosition    = base.transform.position;
        bool    useBodyPosition = false;

        if (this.setup && this.setup.ai && this.setup.ai.pale && !p.IsDummyLoad && this.health.trapGo)
        {
            trapTrigger componentInChildren = this.health.trapGo.GetComponentInChildren <trapTrigger>();
            if (componentInChildren)
            {
                componentInChildren.FixPalePosition(this.setup, false);
                bodyPosition   += -0.15f * Vector3.up;
                useBodyPosition = true;
            }
        }
        GameObject dummy = UnityEngine.Object.Instantiate <GameObject>(this.dummyMutant, bodyPosition, base.transform.rotation);

        dummy.transform.rotation = angle;
        if (p.IsDummyLoad || (this.animator.GetBool("trapBool") && this.animator.GetInteger("trapTypeInt1") == 2))
        {
            dummy.transform.localEulerAngles = new Vector3(0f, dummy.transform.localEulerAngles.y, 0f);
        }
        dummy.transform.localScale = this.mutantBase.localScale;
        dummy.SendMessage("setCalledFromDeath", SendMessageOptions.DontRequireReceiver);
        SkinnedMeshRenderer[] sk = dummy.GetComponentsInChildren <SkinnedMeshRenderer>();
        foreach (SkinnedMeshRenderer skinnedMeshRenderer in sk)
        {
            skinnedMeshRenderer.enabled = false;
        }
        Animator          dummyAnim = dummy.GetComponent <Animator>();
        AnimatorStateInfo state     = this.animator.GetCurrentAnimatorStateInfo(0);

        dummyAnim.CrossFade(state.nameHash, 0f, 0, state.normalizedTime);
        dummyAnim.CopyParamsFrom(this.animator);
        if (p.IsDummyLoad)
        {
            if (this.animator.GetInteger("trapTypeInt1") != 3)
            {
                dummyAnim.SetBoolReflected("trapBool", true);
                if (this.animator.GetInteger("trapTypeInt1") == 2)
                {
                    dummyAnim.SetBoolReflected("enterTrapBool", true);
                    dummyAnim.SetBoolReflected("deathBOOL", true);
                }
                else
                {
                    dummyAnim.SetTriggerReflected("deathTrigger");
                }
            }
        }
        this.dummyHips.rotation    = this.hips.rotation;
        this.dummyHips.position    = bodyPosition;
        dummy.transform.position   = bodyPosition;
        dummy.transform.localScale = this.mutantBase.localScale;
        if (this.setup.health.Fire.Length > 0)
        {
            mutantTransferFire component = base.transform.GetComponent <mutantTransferFire>();
            foreach (GameObject gameObject in this.setup.health.Fire)
            {
                if (gameObject.activeSelf)
                {
                    component.transferFireToTarget(gameObject, dummy);
                }
            }
        }
        if (p.IsDummyLoad || this.animator.GetBool("trapBool"))
        {
            if (this.animator.GetInteger("trapTypeInt1") == 2 && this.health.trapParent)
            {
                dummy.transform.parent = this.health.trapParent.transform;
                dummy.SendMessageUpwards("setTrapDummy", dummy);
                CoopMutantDummy componentInChildren2 = dummy.GetComponentInChildren <CoopMutantDummy>();
                if (componentInChildren2 && this.health.trapGo)
                {
                    this.health.trapGo.SendMessage("SetNooseRope", componentInChildren2, SendMessageOptions.DontRequireReceiver);
                }
            }
            if ((p.IsDummyLoad || this.animator.GetInteger("trapTypeInt1") == 0) && this.health.trapGo)
            {
                this.health.trapGo.SendMessage("addTrappedMutant", new object[]
                {
                    dummy,
                    this.setup
                }, SendMessageOptions.DontRequireReceiver);
                dummy.SendMessage("setTrapGo", this.health.trapGo, SendMessageOptions.DontRequireReceiver);
            }
        }
        string TYPE   = string.Empty;
        bool   skinny = false;

        dummy.SendMessage("invokePickupSpawn", SendMessageOptions.DontRequireReceiver);
        if (this.setup.ai.femaleSkinny)
        {
            skinny = true;
            dummy.SendMessage(TYPE = "setFemaleSkinny", base.transform);
        }
        if (this.setup.ai.maleSkinny)
        {
            skinny = true;
            if (this.setup.ai.pale)
            {
                dummy.SendMessage(TYPE = "enableMaleSkinnyPaleProps");
                dummy.SendMessage(TYPE = "setMaleSkinnyPale", base.transform);
                if (this.setup.ai.skinned)
                {
                    dummy.SendMessage(TYPE = "setSkinnedMutant", this.setup.ai.skinned);
                }
            }
            else
            {
                dummy.SendMessage(TYPE = "enableMaleSkinnyProps");
                dummy.SendMessage(TYPE = "setMaleSkinny", base.transform);
            }
        }
        if (this.setup.ai.pale && !this.setup.ai.maleSkinny)
        {
            dummy.SendMessage(TYPE = "enablePaleProps");
            dummy.SendMessage(TYPE = "setPaleMale");
            if (this.setup.ai.skinned)
            {
                dummy.SendMessage(TYPE = "setSkinnedMutant", this.setup.ai.skinned);
            }
        }
        if (this.setup.ai.leader && !this.setup.ai.maleSkinny && !this.setup.ai.pale && !this.setup.ai.female)
        {
            dummy.SendMessage(TYPE = "setRegularMale", this.setup.propManager ? this.setup.propManager.regularMaleDice : 0);
            dummy.SendMessage(TYPE = "enableLeaderProps", this.setup.propManager ? this.setup.propManager.LeaderDice : 0);
            if (this.setup.ai.painted)
            {
                dummy.SendMessage(TYPE = "setPaintedLeader");
            }
            dummy.SendMessage(TYPE = "setRegularMaleLeader");
        }
        if (this.setup.ai.fireman)
        {
            if (this.setup.ai.fireman_dynamite)
            {
                dummy.SendMessage(TYPE = "setDynamiteMan");
            }
            dummy.SendMessage(TYPE = "enableFiremanProps");
            dummy.SendMessage(TYPE = "setRegularMaleFireman");
        }
        if (this.setup.ai.female && !this.setup.ai.femaleSkinny)
        {
            if (this.setup.ai.painted)
            {
                dummy.SendMessage(TYPE = "setFemalePainted", this.setup.bodyVariation ? this.setup.bodyVariation.femaleDice : 0);
            }
            else
            {
                dummy.SendMessage(TYPE = "setFemaleRegular", this.setup.bodyVariation ? this.setup.bodyVariation.femaleDice : 0);
            }
            if (this.bodyVar && this.bodyVar.Hair && this.bodyVar.Hair.activeSelf)
            {
                dummy.SendMessage(TYPE = "setFemaleHair");
            }
            if (this.bodyVar && this.bodyVar.Clothing && this.bodyVar.Clothing.activeSelf)
            {
                dummy.SendMessage(TYPE = "setFemaleClothes");
            }
            if (this.bodyVar && this.bodyVar.FireDice == 2)
            {
                dummy.SendMessage(TYPE = "setFemaleFire");
            }
        }
        if (this.setup.ai.male && !this.setup.ai.maleSkinny && !this.setup.ai.pale && !this.setup.ai.fireman && !this.setup.ai.leader)
        {
            if (this.setup.ai.painted)
            {
                dummy.SendMessage(TYPE = "setPaintedMale", this.setup.propManager ? this.setup.propManager.regularMaleDice : 0);
            }
            else
            {
                dummy.SendMessage(TYPE = "setRegularMale", this.setup.propManager ? this.setup.propManager.regularMaleDice : 0);
            }
        }
        if (this.setup.health.alreadyBurnt)
        {
            dummy.SendMessage("setBurntSkin", SendMessageOptions.DontRequireReceiver);
        }
        dummy.SendMessage("setPoisoned", this.health.poisoned, SendMessageOptions.DontRequireReceiver);
        if (this.setup.arrowSticker)
        {
            arrowStickToTarget componentInChildren3 = dummy.GetComponentInChildren <arrowStickToTarget>();
            foreach (KeyValuePair <Transform, int> keyValuePair in this.setup.arrowSticker.stuckArrows)
            {
                if (keyValuePair.Key)
                {
                    componentInChildren3.applyStuckArrowToDummy(keyValuePair.Key, keyValuePair.Key.localPosition, keyValuePair.Key.localRotation, keyValuePair.Value);
                }
            }
        }
        this.setup.health.MySkin.GetPropertyBlock(this.bloodPropertyBlock);
        dummy.SendMessage("setSkinDamageProperty", this.bloodPropertyBlock, SendMessageOptions.DontRequireReceiver);
        dummy.SendMessage("setSkinMaterialProperties", this.health.MySkin.material, SendMessageOptions.DontRequireReceiver);
        if (BoltNetwork.isServer)
        {
            CoopMutantDummyToken coopMutantDummyToken = new CoopMutantDummyToken();
            coopMutantDummyToken.Skinny         = skinny;
            coopMutantDummyToken.HipPosition    = bodyPosition;
            coopMutantDummyToken.HipRotation    = this.hips.rotation;
            coopMutantDummyToken.OriginalMutant = base.GetComponent <BoltEntity>();
            coopMutantDummyToken.Scale          = this.mutantBase.localScale;
            coopMutantDummyToken.skinDamage1    = this.bloodPropertyBlock.GetFloat("_Damage1");
            coopMutantDummyToken.skinDamage2    = this.bloodPropertyBlock.GetFloat("_Damage2");
            coopMutantDummyToken.skinDamage3    = this.bloodPropertyBlock.GetFloat("_Damage3");
            coopMutantDummyToken.skinDamage4    = this.bloodPropertyBlock.GetFloat("_Damage4");
            if (p.IsDummyLoad)
            {
                foreach (SkinnedMeshRenderer skinnedMeshRenderer2 in sk)
                {
                    skinnedMeshRenderer2.enabled = true;
                }
                CoopMutantMaterialSync component2 = dummy.GetComponent <CoopMutantMaterialSync>();
                component2.ForceStart();
                coopMutantDummyToken.MaterialIndex = component2.GetMaterialIndex();
                CoopMutantPropSync component3 = dummy.GetComponent <CoopMutantPropSync>();
                coopMutantDummyToken.Props = component3.GetPropMask();
            }
            else
            {
                IMutantState state2 = base.GetComponent <BoltEntity>().GetState <IMutantState>();
                coopMutantDummyToken.MaterialIndex = state2.MainMaterialIndex;
                coopMutantDummyToken.Props         = state2.prop_mask;
            }
            if (this.health.poisoned)
            {
                coopMutantDummyToken.skinColor = new Color(0.670588255f, 0.796078444f, 0.5529412f, 1f);
            }
            else if (this.setup.ai.pale && !this.setup.ai.skinned)
            {
                coopMutantDummyToken.skinColor = new Color(0.8039216f, 0.870588243f, 0.9137255f, 1f);
            }
            else
            {
                coopMutantDummyToken.skinColor = new Color(0.698039234f, 0.698039234f, 0.698039234f, 1f);
            }
            BoltNetwork.Attach(dummy, coopMutantDummyToken);
        }
        if (BoltNetwork.isServer)
        {
            IMutantFemaleDummyState mutantFemaleDummyState;
            if (dummy.GetComponent <BoltEntity>().TryFindState <IMutantFemaleDummyState>(out mutantFemaleDummyState))
            {
                mutantFemaleDummyState.Type          = TYPE;
                mutantFemaleDummyState.CrossFadeHash = state.nameHash;
                mutantFemaleDummyState.CrossFadeTime = state.normalizedTime;
            }
            IMutantMaleDummyState mutantMaleDummyState;
            if (dummy.GetComponent <BoltEntity>().TryFindState <IMutantMaleDummyState>(out mutantMaleDummyState))
            {
                mutantMaleDummyState.Type          = TYPE;
                mutantMaleDummyState.CrossFadeHash = state.nameHash;
                mutantMaleDummyState.CrossFadeTime = state.normalizedTime;
            }
        }
        List <Quaternion> jointRotations = new List <Quaternion>();

        for (int l = 0; l < this.mrs.jointsToSync.Length; l++)
        {
            jointRotations.Add(this.mrs.jointsToSync[l].localRotation);
        }
        if (!p.IsDummyLoad && !this.animator.GetBool("trapBool"))
        {
            dummy.SendMessage("syncRagDollJoints", jointRotations, SendMessageOptions.DontRequireReceiver);
        }
        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        dummy.transform.localScale = this.mutantBase.localScale;
        dummy.transform.position   = ((!useBodyPosition) ? this.DeadPosition : bodyPosition);
        if (this.animator.GetBool("trapBool") && this.animator.GetInteger("trapTypeInt1") == 2)
        {
            this.setup.rootTr.parent = null;
        }
        foreach (SkinnedMeshRenderer skinnedMeshRenderer3 in sk)
        {
            skinnedMeshRenderer3.enabled = true;
        }
        if (PoolManager.Pools["enemies"].IsSpawned(base.transform))
        {
            PoolManager.Pools["enemies"].Despawn(base.transform);
        }
        else if (BoltNetwork.isServer)
        {
            dummy.GetComponent <BoltEntity>().DestroyDelayed(0.1f);
        }
        else
        {
            UnityEngine.Object.Destroy(base.transform.gameObject);
        }
        yield return(null);

        yield break;
    }
    void Start()
    {
        animator = GetComponent<Animator>();

        eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();

        continueButton = GameObject.Find("Panel/Main/ContinueButton").GetComponent<Button>();
        continueButton.onClick.AddListener(ContinueGame);

        newGameButton = GameObject.Find("Panel/Main/NewGameButton").GetComponent<Button>();
        newGameButton.onClick.AddListener(NewGame);

        optionsButton = GameObject.Find("Panel/Main/OptionsButton").GetComponent<Button>();
        optionsButton.onClick.AddListener(EnterOptions);

        exitButton = GameObject.Find("Panel/Main/ExitButton").GetComponent<Button>();
        exitButton.onClick.AddListener(Exit);

        backButton = GameObject.Find("Panel/Options/BackButton").GetComponent<Button>();
        backButton.onClick.AddListener(LeaveOptions);

        yesButton = GameObject.Find("Panel/Override/YesButton").GetComponent<Button>();
        yesButton.onClick.AddListener(ConfirmOverride);

        noButton = GameObject.Find("Panel/Override/NoButton").GetComponent<Button>();
        noButton.onClick.AddListener(CancelOverride);

        musicVolumeSlider = GameObject.Find("Panel/Options/MusicSlider").GetComponent<Slider>();
        musicVolumeSlider.onValueChanged.AddListener(Utils.ChangeMusicVolume);

        sfxVolumeSlider = GameObject.Find("Panel/Options/SFXSlider").GetComponent<Slider>();
        sfxVolumeSlider.onValueChanged.AddListener(Utils.ChangeSfxVolume);

        granny = GameObject.Find("Granny").GetComponent<PlayerController>();

        PlayerController.IsAttacking = false; //quick fix

        levelEntries = GameObject.FindObjectsOfType<LevelEntry>();

        if (GameProgress.Instance.Level == 0)
        {
            continueButton.interactable = false;
        }

        if (ShowLevelSelection)
        {
            animator.SetBool("LevelSelect", true);
            animator.CrossFade("MainLevelSelect", 0.0f);

            granny.IsControllable = true;
        }
        else
        {
            granny.IsControllable = false;

            selectLeftButton();
        }
    }
Esempio n. 16
0
 private void ChangeFace(string str)
 {
     isKeepFace = true;
     current    = 1;
     anim.CrossFade(str, 0);
 }
Esempio n. 17
0
 private void Charge()
 {
     anim.CrossFade(chargeState, 0f);                    // triggers are unreliable, crossfade forces state to execute
     body.Move(Vector2.zero);
     //+ new Vector2(Random.value, Random.value);		// add a random offset
 }
Esempio n. 18
0
 public void StopWeapon()
 {
     m_Animator.CrossFade("Idle", 0.2f);
     DisableDamage();
 }
Esempio n. 19
0
    void Update()
    {
        baiduapi = gameObject.GetComponent <TestBaidu>();
        AudioSource audio1 = audioObject.GetComponent <AudioSource>();

        // baiduapi.StartListen_bool();
        if (baiduapi._isListen)
        {
            baiduapi.StartVoice("{\"accept-audio-data\":true,\"vad.endpoint-timeout\":0,\"vad\":dnn,\"pid\":15361,\"disable-punctuation\":false,\"accept-audio-volume\":true}");
        }
        if (Input.GetKeyDown(KeyCode.Q))
        //if (baiduapi._isListen)
        // if (audio1.isPlaying)
        // if(audio1.clip)
        {
            anim.CrossFade("Stand", 0.1f);
            anim.SetBool("iswave", true);
            anim.SetBool("isstand", false);
            Debug.Log("wozaikongzhi");
        }
        else
        {
            anim.SetBool("iswave", false);
            anim.SetBool("isstand", true);
        }

// key control

        if (Input.GetKeyDown(KeyCode.Q))
        {
            anim.CrossFade("Stand", 0.1f);
            anim.SetBool("iswave", true);
            anim.SetBool("isstand", false);
        }
        else
        {
            anim.SetBool("iswave", false);
            anim.SetBool("isstand", true);
        }
        //if (Input.GetKeyDown(KeyCode.S))
        //{
        //    anim.CrossFade("Combine1", 0.1f);

        //}
        if (Input.GetKeyDown(KeyCode.W))
        {
            anim.CrossFade("Stand", 0.1f);
            anim.SetBool("iscom1", true);
            anim.SetBool("isstand1", false);
        }
        else
        {
            anim.SetBool("iscom1", false);
            anim.SetBool("isstand1", true);
        }
        // if (Input.GetKeyDown(KeyCode.D))
        // {
        //     anim.CrossFade("Combine2", 0.1f);

        //  }
        if (Input.GetKeyDown(KeyCode.E))
        {
            anim.CrossFade("Stand", 0.1f);
            anim.SetBool("iscom2", true);
            anim.SetBool("isstand2", false);
        }
        else
        {
            anim.SetBool("iscom2", false);
            anim.SetBool("isstand2", true);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            anim.CrossFade("Stand", 0.1f);
            anim.SetBool("isran1", true);
            anim.SetBool("isstand3", false);
        }
        else
        {
            anim.SetBool("isran1", false);
            anim.SetBool("isstand3", true);
        }
    }
Esempio n. 20
0
    private void _playAnimation(AnimationData targetAnimationData, float blendingTime, float normalizedTime, bool mirror)
    {
        //The overrite machine. Creates an overrideController, replace its core animations and restate it back in
        ////("cyan", "_playAnimation:"+targetAnimationData.clipName);
        if (targetAnimationData == null || targetAnimationData.clip == null)
        {
            return;
        }
        if (currentAnimationData == null)
        {
            Debug.LogError("_playAnimation :currentAnimationData == null!");
            return;
        }

        if (currentAnimationData.clipName != targetAnimationData.clipName)
        {
            SetOverrideController(currentAnimationData, targetAnimationData, mirror);
        }

        float newAnimatorSpeed      = Mathf.Abs(targetAnimationData.speed) * speed;
        float currentNormalizedTime = GetNormalizedTime();

        if (blendingTime == -1)
        {
            blendingTime = currentAnimationData.transitionDuration;
        }
        if (blendingTime == -1)
        {
            blendingTime = defaultTransitionDuration;
        }
        currentBlendingTime = blendingTime;

        if (blendingTime <= 0 || currentAnimationData.clip == targetAnimationData.clip)
        {
            //Util.LogColor("red", modelName + "play:" + targetAnimationData.clipName);
            //animator.Rebind();
            AnimatorPlay("State2", 0, normalizedTime);
        }
        else
        {
            //Util.LogColor("cyan", modelName + "crossfade:" + targetAnimationData.clipName+ "blendingTime:"+ blendingTime);
            currentAnimationData.stateName = "State1";
            SetCurrentClipPosition(currentNormalizedTime);
            animator.Update(0);
            animator.CrossFade("State2", blendingTime / newAnimatorSpeed);
        }


        targetAnimationData.timesPlayed   = 0;
        targetAnimationData.secondsPlayed = (normalizedTime * targetAnimationData.clip.length) / newAnimatorSpeed;
        targetAnimationData.length        = targetAnimationData.clip.length;

        if (overrideRootMotion)
        {
            animator.applyRootMotion = targetAnimationData.applyRootMotion;
        }
        SetSpeed(targetAnimationData.speed);

        currentAnimationData           = targetAnimationData;
        currentAnimationData.stateName = "State2";
        //currentAnimationData.stateHash = state2Hash;

        if (MecanimControl.OnAnimationBegin != null)
        {
            MecanimControl.OnAnimationBegin(currentAnimationData);
        }
    }
Esempio n. 21
0
    void Update()
    {
        float SpeedTyper = 1.1f;
        float vel        = Body.velocity.magnitude;
        float MoverTyper = 15;


        Vector2 VectorVel = Body.velocity;
        float   Direct    = transform.InverseTransformDirection(VectorVel).y;

        if (Direct < 0)
        {
            Direct = -1;
        }
        else
        {
            Direct = 1;
        }
        //Debug.Log("На, сука: " + Direct);

/* ============================ AUTO MOTOR BOX ============================== */
        if (Input.GetKey(KeyCode.W))
        {
            //Первая
            if (vel <= 1)
            {
                SpeedTyper = SpeedTyper * 1;
                Motor.AddRelativeForce(Vector2.up * speed * SpeedTyper);
            }
            //Вторая
            if (vel > 1 && vel <= 8)
            {
                SpeedTyper = SpeedTyper * 2.5f;
                Motor.AddRelativeForce(Vector2.up * speed * SpeedTyper);
            }
            //Третья
            if (vel > 8)
            {
                SpeedTyper = SpeedTyper * 5;
                Motor.AddRelativeForce(Vector2.up * speed * SpeedTyper);
            }
        }
/*=============================== BACK MOVE ================================= */
        if (Input.GetKey(KeyCode.S))
        {
            //Тормоз на скорости
            if (vel > 15)
            {
                SpeedTyper = SpeedTyper * 5;
                Motor.AddRelativeForce(Vector2.down * speed * SpeedTyper);
            }
            //Тихий Задний Ход
            if (vel <= 15)
            {
                SpeedTyper = SpeedTyper * 2;
                Motor.AddRelativeForce(Vector2.down * speed * SpeedTyper);
            }
        }


/*============================ ЛЕВЫЙ ПОВОРОТНИК ============================= */
        if (Input.GetKey(KeyCode.A))
        {
            Anim.CrossFade("Left", 0.3f);
            // На малых оборотах
            if (vel > 3 && vel <= 15)
            {
                float MoverTyperI = MoverTyper * 10;
                Mover.AddRelativeForce(Vector2.left * vel * MoverTyperI * Direct);
            }
            // На скорости
            if (vel > 15)
            {
                float MoverTyperII = MoverTyper * 5;
                Mover.AddRelativeForce(Vector2.left * vel * MoverTyperII * Direct);
            }
        }
        if (Input.GetKeyUp(KeyCode.A))
        {
            Anim.CrossFade("Idle", 0.3f);
        }


/*============================= ПРАВЫЙ ПОВОРОТНИК =========================== */
        if (Input.GetKey(KeyCode.D))
        {
            Anim.CrossFade("Right", 0.3f);
            // На малых оборотах
            if (vel > 3 && vel <= 15)
            {
                float MoverTyperI = MoverTyper * 10;
                Mover.AddRelativeForce(Vector2.right * vel * MoverTyperI * Direct);
            }
            // На скорости
            if (vel > 15)
            {
                float MoverTyperII = MoverTyper * 5;
                Mover.AddRelativeForce(Vector2.right * vel * MoverTyperII * Direct);
            }
        }
        if (Input.GetKeyUp(KeyCode.D))
        {
            Anim.CrossFade("Idle", 0.3f);
        }
/*=============================== CAM SIZE ===================================*/
        DifSize = Mathf.SmoothDamp(DifSize, Body.velocity.magnitude * 0.5f, ref SizerSpeed, 1f);
        Camera.main.orthographicSize = 5.0f + DifSize;
/*============================================================================*/
    }
Esempio n. 22
0
        /// <summary>
        /// Called when the actor takes damage. This allows the actor to respond.
        /// Damage Type 0 = Physical melee
        /// Damage Type 1 = Physical ranged
        /// </summary>
        /// <param name="rDamageValue">Amount of damage to take</param>
        /// <param name="rDamageType">Damage type taken</param>
        /// <param name="rAttackAngle">Angle that the damage came from releative to the actor's forward</param>
        /// <param name="rDamagedMotion">Motion to activate due to damage</param>
        /// <param name="rDeathMotion">Motion to activate due to death</param>
        /// <returns>Determines if the damage was applied</returns>
        public virtual bool OnDamaged(IMessage rMessage)
        {
            if (!IsAlive)
            {
                return(true);
            }

            float lRemainingHealth = 0f;

            if (AttributeSource != null)
            {
                if (rMessage is DamageMessage)
                {
                    lRemainingHealth = AttributeSource.GetAttributeValue(HealthID) - ((DamageMessage)rMessage).Damage;
                    AttributeSource.SetAttributeValue(HealthID, lRemainingHealth);
                }
            }

            if (lRemainingHealth <= 0f)
            {
                OnKilled(rMessage);
            }
            else if (rMessage != null)
            {
                bool lPlayAnimation = true;
                if (rMessage is DamageMessage)
                {
                    lPlayAnimation = ((DamageMessage)rMessage).AnimationEnabled;
                }

                if (lPlayAnimation)
                {
                    MotionController lMotionController = gameObject.GetComponent <MotionController>();
                    if (lMotionController != null)
                    {
                        // Send the message to the MC to let it activate
                        rMessage.ID = CombatMessage.MSG_DEFENDER_DAMAGED;
                        lMotionController.SendMessage(rMessage);
                    }

                    if (!rMessage.IsHandled && DamagedMotion.Length > 0)
                    {
                        MotionControllerMotion lMotion = lMotionController.GetMotion(DamagedMotion);
                        if (lMotion != null)
                        {
                            lMotionController.ActivateMotion(lMotion);
                        }
                        else
                        {
                            Animator lAnimator = gameObject.GetComponent <Animator>();
                            if (lAnimator != null)
                            {
                                lAnimator.CrossFade(DamagedMotion, 0.25f);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 23
0
 private void Jump()
 {
     if (player.state.lastVertical > 0 && player.state.grounded)
     {
         player.state.grounded = false;
         GetComponent <Rigidbody>().velocity = new Vector3(0, jumpVelocity);
         if (player.state.idle)
         {
             playerAnimator.CrossFade("StaticJump", 0.2f);
         }
         else
         {
             playerAnimator.CrossFade("MovingJump", 0.2f);
         }
     }
 }
Esempio n. 24
0
 public void PlayAnimation(string animName)
 {
     anim.CrossFade(animName, 0);
 }
Esempio n. 25
0
        void Update()
        {
            enableRM            = !ani.GetBool("canMove"); //canMove Bool 값
            ani.applyRootMotion = enableRM;

            interacting = ani.GetBool("interacting");

            if (lockon == false)
            {
                horizontal = 0;
                vertical   = Mathf.Clamp01(vertical);
            }
            ani.SetBool("lockon", lockon);

            if (enableRM)
            {
                return;
            }

            if (useItem)              //아이템을 사용할때
            {
                ani.Play("use_item"); //아이템 사용 모션을 취함
                useItem = false;      //아이템사용후 모션 끝
            }

            if (interacting)
            {
                playAni  = false;
                vertical = Mathf.Clamp(vertical, 0, 0.5f); //수직 움직임 정수값
            }

            ani.SetBool("two_handed", twoHanded); // 양손 파라메터

            if (playAni)
            {
                string targetAni; //애니메이션 문자열 선언

                if (!twoHanded)
                {
                    int r = Random.Range(0, oh_attacks.Length);
                    targetAni = oh_attacks[r];

                    if (vertical > 0.5f)           // 이동속도가 0.5보다 빠르게 달리면
                    {
                        targetAni = "oh_attack_3"; //양손 아니더라도 3번째 공격모션
                    }
                }
                else
                {
                    int r = Random.Range(0, th_attacks.Length);
                    targetAni = th_attacks[r];
                }

                if (vertical > 0.5f)           // 이동속도가 0.5보다 빠르게 달리면
                {
                    targetAni = "oh_attack_3"; //3번째 공격모션
                }
                vertical = 0;                  //움직임 0


                ani.CrossFade(targetAni, 0.2f); //애니메이션 블렌딩 , 변경할 애니메이션 클립(1), 다른 애니메이션으로 페이드 아웃 0.2초(2)
                //ani.SetBool("canMove",false);
                //enableRM = true;
                playAni = false;
            }
            ani.SetFloat("vertical", vertical);     //수직 속도
            ani.SetFloat("horizontal", horizontal); //수평 속도
        }
    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();
    }
Esempio n. 27
0
 void OnChangeAction(string animeId)
 {
     animator.CrossFade(animeId, 0.15f, 0, 0f);
 }
Esempio n. 28
0
 void SelectAnimation(string name)
 {
     rigAnimator.CrossFade(name, animationBlendSpeed);
 }
Esempio n. 29
0
    public void Kick()
    {
        var state             = Animator.GetCurrentAnimatorStateInfo(0);
        var playingKick       = state.IsName("Kick");
        var playingKickRepeat = state.IsName("KickRepeat");
        var playingSnare      = state.IsName("Snare") || state.IsName("SnareRepeat");

        if (!playingKick && !playingKickRepeat)
        {
            Animator.Play("Kick", 0, 0f);
        }
        else if (playingKick)
        {
            Animator.CrossFade("KickRepeat", 0.05f, 0, 0.115f);
        }
        else if (playingKickRepeat)
        {
            Animator.CrossFade("Kick", 0.05f, 0, 0.115f);
        }
        else if (playingSnare)
        {
            Animator.CrossFade("Snare", 0.05f, 0, 0.052f);
        }
    }
Esempio n. 30
0
 void OnEnable()
 {
     MyAnimator.CrossFade(AnimationStateName, 0f);
 }
    // Update is called once per frame
    void Update()
    {
        if (rbfps.Grounded)
        {
            rb.drag    = drag_grounded;
            canwallrun = true;
        }
        else
        {
            rb.drag = drag_inair;
        }
        if (WallRunning)
        {
            rb.drag = drag_wallrun;
        }
        //vault
        if (detectVaultObject.Obstruction && !detectVaultObstruction.Obstruction && !CanVault && !IsParkour && !WallRunning &&
            (Input.GetKey(KeyCode.Space) || !rbfps.Grounded) && Input.GetAxisRaw("Vertical") > 0f)
        // if detects a vault object and there is no wall in front then player can pressing space or in air and pressing forward
        {
            CanVault = true;
        }

        if (CanVault)
        {
            CanVault               = false; // so this is only called once
            rb.isKinematic         = true;  //ensure physics do not interrupt the vault
            RecordedMoveToPosition = VaultEndPoint.position;
            RecordedStartPosition  = transform.position;
            IsParkour              = true;
            chosenParkourMoveTime  = VaultTime;

            cameraAnimator.CrossFade("Vault", 0.1f);
        }

        //climb
        if (detectClimbObject.Obstruction && !detectClimbObstruction.Obstruction && !CanClimb && !IsParkour && !WallRunning &&
            (Input.GetKey(KeyCode.Space) || !rbfps.Grounded) && Input.GetAxisRaw("Vertical") > 0f)
        {
            CanClimb = true;
        }

        if (CanClimb)
        {
            CanClimb               = false; // so this is only called once
            rb.isKinematic         = true;  //ensure physics do not interrupt the vault
            RecordedMoveToPosition = ClimbEndPoint.position;
            RecordedStartPosition  = transform.position;
            IsParkour              = true;
            chosenParkourMoveTime  = ClimbTime;

            cameraAnimator.CrossFade("Climb", 0.1f);
        }


        //Parkour movement
        if (IsParkour && t_parkour < 1f)
        {
            t_parkour         += Time.deltaTime / chosenParkourMoveTime;
            transform.position = Vector3.Lerp(RecordedStartPosition, RecordedMoveToPosition, t_parkour);

            if (t_parkour >= 1f)
            {
                IsParkour      = false;
                t_parkour      = 0f;
                rb.isKinematic = false;
            }
        }


        //Wallrun
        if (DetectWallL.Obstruction && !rbfps.Grounded && !IsParkour && canwallrun) // if detect wall on the left and is not on the ground and not doing parkour(climb/vault)
        {
            WallrunningLeft = true;
            canwallrun      = false;
            upforce         = WallRunUpForce;
        }

        if (DetectWallR.Obstruction && !rbfps.Grounded && !IsParkour && canwallrun) // if detect wall on thr right and is not on the ground
        {
            WallrunningRight = true;
            canwallrun       = false;
            upforce          = WallRunUpForce;
        }
        if (WallrunningLeft && !DetectWallL.Obstruction || Input.GetAxisRaw("Vertical") <= 0f || rbfps.relativevelocity.magnitude < 1f) // if there is no wall on the lef tor pressing forward or forward speed < 1 (refer to fpscontroller script)
        {
            WallrunningLeft  = false;
            WallrunningRight = false;
        }
        if (WallrunningRight && !DetectWallR.Obstruction || Input.GetAxisRaw("Vertical") <= 0f || rbfps.relativevelocity.magnitude < 1f) // same as above
        {
            WallrunningLeft  = false;
            WallrunningRight = false;
        }

        if (WallrunningLeft || WallrunningRight)
        {
            WallRunning       = true;
            rbfps.Wallrunning = true; // this stops the playermovement (refer to fpscontroller script)
        }
        else
        {
            WallRunning       = false;
            rbfps.Wallrunning = false;
        }

        if (WallrunningLeft)
        {
            cameraAnimator.SetBool("WallLeft", true); //Wallrun camera tilt
        }
        else
        {
            cameraAnimator.SetBool("WallLeft", false);
        }
        if (WallrunningRight)
        {
            cameraAnimator.SetBool("WallRight", true);
        }
        else
        {
            cameraAnimator.SetBool("WallRight", false);
        }

        if (WallRunning)
        {
            rb.AddRelativeForce(0f, upforce, 0f);
            upforce -= WallRunUpForce_DecreaseRate * Time.deltaTime; //so the player will have a curve like wallrun

            if (Input.GetKeyDown(KeyCode.Space))
            {
                rb.velocity      = transform.forward * WallJumpForwardVelocity + transform.up * WallJumpUpVelocity; //walljump
                WallrunningLeft  = false;
                WallrunningRight = false;
            }
            if (rbfps.Grounded)
            {
                WallrunningLeft  = false;
                WallrunningRight = false;
            }
        }
    }
Esempio n. 32
0
 // Update is called once per frame
 void Update()
 {
     anim.CrossFade(globals.price_for_diamonds_panel_slot_0_predmet_name, 0);
     //Аналог if (globals.price_for_diamonds_panel_slot_0_predmet_name == "egg") { anim.CrossFade("egg", 0); }
 }
    void Awake(){

        panda_audio = this.gameObject.AddComponent<AudioSource>();
        panda_audio.playOnAwake = false;
        panda_audio.loop = false;

		enu_audio = this.gameObject.AddComponent<AudioSource>();
		enu_audio.playOnAwake = false;
		enu_audio.loop = false;

        //		player = GetComponentInParent<Animator>();
        last_trap_obj = null;
		transform = GetComponentInParent<Transform> ();
		player = transform.Find("panda").gameObject.GetComponentInParent<Animator>();
		left_check = transform.Find(LEFT_CHECK);
		right_check = transform.Find(RIGHT_CHECK);
		up_check = transform.Find(UP_CHECK);
		down_check = transform.Find(DOWN_CHECK);
			
		if (stand_direction == 1) {

			player.CrossFade ("down", 0);

		} else if (stand_direction == 2) {
			player.CrossFade ("stand_",0);

		}else if(stand_direction == 3){

			player.CrossFade ("left_stand_",0);
		}else if(stand_direction == 4){
			player.CrossFade ("right_stand_",0);
		}
	}
Esempio n. 34
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey("escape"))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }


        if (estadoJuego != estadoJuegoOld)
        {
            estadoJuegoOld = estadoJuego;
            if (estadoJuego == "inicio")
            {
                estadoJuego     = "juego";
                tiempo          = default_time;
                assault.enabled = true;                 //TENTACULOS Encendidos
            }
        }
        if (estadoPaneles != estadoPanelesOld)
        {
            estadoPanelesOld = estadoPaneles;
            if (estadoPaneles == "inicio")
            {
                musica.crossfade(0);                 //beginning song
            }
            if (estadoPaneles == "win")
            {
                musica.crossfade(1);
            }
            if (estadoPaneles == "hud")
            {
                musica.crossfade(2, 5);     //enemies song
                fx.play(3);                 //mike
            }
            if (estadoPaneles == "fin")
            {
                musica.crossfade(3);
            }
            foreach (GameObject panel in Paneles)
            {
                if (panel.name == estadoPaneles)
                {
                    panel.SetActive(true);
                }
                else
                {
                    panel.SetActive(false);
                }
            }
        }

        if (puzzle.solved == true)
        {
            if (!antenaAnimFlag)
            {
                antenaAnimFlag = true;
                animAntena.CrossFade("on", 1);
            }
        }



        if (estadoJuego == "juego")
        {
            if (defence.close)
            {
                CanvasAlert.SetActive(true);
            }
            else
            {
                CanvasAlert.SetActive(false);
            }
            if (defence.alive == false)
            {
                finMalo();
            }
        }
    }
 public void PlayAnim(string animToPlay)
 {
     anim.CrossFade(animToPlay, 0.3f);
 }
Esempio n. 36
0
 internal void TransitionToAttacking(Vector3 syncLoc, Quaternion syncRot, float time)
 {
     anim.CrossFade("mutant_swiping", 0.1f);
     anim.applyRootMotion = true;
     StartSyncTo(syncLoc, syncRot, time);
 }
 void FastForwardAnimator(Animator animator, float second, float crossfade)
 {
     for (var layer = 0; layer < animator.layerCount; layer++)
     {
         var info = animator.GetCurrentAnimatorStateInfo(layer);
         if (crossfade > 0.0f)
             animator.CrossFade(info.nameHash, crossfade / info.length, layer, info.normalizedTime + second / info.length);
         else
             animator.Play(info.nameHash, layer, info.normalizedTime + second / info.length);
     }
 }
Esempio n. 38
0
        //坑爹,动态加动画事件的时候,播放到事件帧时,会跳过该transition
        //这里让它接着上次跳过的事件帧断点播放一次
        private IEnumerator playBreakpoint()
        {
            yield return(null);

            _animator.CrossFade(_stateHash, 0.01f, 0, _breakTime - 2 * Time.deltaTime);
        }
Esempio n. 39
0
    // Update is called once per frame
    void Update()
    {
        if (target != position && !triggered)
        {
            anim.CrossFade("OldWoman_Walk", 0);
            position = gameObject.transform.position;
            float step = Time.deltaTime * speed;
            //  Debug.Log(step);
            // anim.CrossFade("Old_Man_Walk", 0);

            // Debug.Log(position2.x - gameObject.transform.position.x);

            if (position2.x - gameObject.transform.position.x > 0)
            {
                sr.flipX = true;
            }
            else
            {
                sr.flipX = false;
            }

            transform.position = Vector2.MoveTowards(transform.position, target, step);

            //For loop for all of the destination points and create a vector of destinations
            //Debug.Log("shit");
        }

        else if (!triggered)
        {
            anim.CrossFade("oldWoman_Idle", 0);
            StartCoroutine("MoveManager");
        }


        if (triggered)
        {
            //anim.CrossFade("Old_woman", 0);
            StopCoroutine("MoveManager");

            //Debug.Log("3: " + index);

            if (index < destinations.Length)
            {
                position = gameObject.transform.position;
                if (destinations[index] != position)
                {
                    // position = gameObject.transform.position;
                    float step = Time.deltaTime * speed;
                    transform.position = Vector2.MoveTowards(transform.position, destinations[index], step);
                    //Debug.Log(destinations[index]);
                }

                else
                {
                    index++;

                    //Debug.Log("2: " + index);
                    //  Debug.Log(destinations.Length);

                    if (index >= destinations.Length)
                    {
                        //anim.CrossFade("oldWoman_Idle", 0);
                        anim.CrossFade("OldWoman_Walk", 0);
                        StartCoroutine("MoveDestManager");
                    }
                }

                //if (destinations[i] == position)n\
                //{

                //    Debug.Log("here");
                //}
            }
            //else
            //{
            //    index = 0;
            //    triggered = false;
            //}

            //for (int i = 0; i < destinations.Length; i++)
            //{



            //}
        }


        //else if(triggered && position == dest && dest2!=null)
        // {
        //     Debug.Log("nice");
        //     position = gameObject.transform.position;
        //     float step = Time.deltaTime * speed;
        //     transform.position = Vector2.MoveTowards(transform.position, dest2, step);

        // }



        //else if(triggered)
        //{
        //    StartCoroutine("MoveSomewhere");
        //}

        // if (transform.position==target)
        //{


        //}


        //ExitPosition = Vector2(xPos, yPos);

        //transform.position = new Vector3(xPos, yPos, 0);

        //if (transform.position.x < 3.0f)
        //{
        //transform.position.x += moveForce * Time.deltaTime;

        //transform.position = Vector2.Lerp(transform.position , ExitPosition, speed * Time.deltaTime);

        //transform.position = new Vector2(xPos, yPos);

        //}
    }
Esempio n. 40
0
 // play animation state.
 // for viewer mode
 public void PlayClip(string stateName)
 {
     chrAnimator.CrossFade(stateName, 0.05f);
 }
Esempio n. 41
0
 // Start is called before the first frame update
 void Start()
 {
     anim = GetComponent <Animator>();
     anim.CrossFade("wheat", 1);
 }
Esempio n. 42
0
    public void Start()
    {
        _guiCanvas = GuiCanvas.Instance;
        _talkingUi = _guiCanvas.TalkingUi;

        _animator = GetComponentInChildren<Animator>();

        _birdProps = BirdPropsService.Instance.GetBirdPropsById(TextId);

        if (_birdProps != null)
        {
            if (_birdProps.AnimatorController != null)
            {
                _animator.runtimeAnimatorController = _birdProps.AnimatorController;
            }

            _animator.CrossFade(_birdProps.DefaultAnim, 0f);
        }
        else
        {
            _birdProps = new BirdProps("Idle", true, null);
        }

        QMark = transform.FindChild("?").gameObject;
        QMark.SetActive(false);

        Directions = DirectionService.Instance.GetDirectionsById(TextId);

        _animator.CrossFade(_birdProps.DefaultAnim, 0f);
        _animator.transform.localScale = 
                _animator.transform.localScale.SetX(_birdProps.FaceLeft ? 1 : -1);


        if (State.Instance.LevelEntrance == LevelEntrance.BeachRival && TextId == "Rival")
        {
            var lossDialog = new List<Direction>
            {
                new Line("Winson \"Collecto\"", "Woof. Erm, Chirp. Not the best dancing I've seen."),
                new Line("Winson \"Collecto\"", "We can go again any time. You may need to practice.")
            };

            var perfectDialog = new List<Direction>
            {
                new Line("Winson \"Collecto\"", "Wow. Just wow. I am very impressed."),
                new Line("Winson \"Collecto\"", "So, about your prize. It's the most prized and valuable thing to my name."),
                new Line("Winson \"Collecto\"", "It's... my respect. You have my respect. Good job guy."),
                new Line("Winson \"Collecto\"", "We can go again any time.")
            };

            var okDialog = new List<Direction>
            {
                new Line("Winson \"Collecto\"", "Pretty good. Not perfect, but pretty good."),
                new Line("Winson \"Collecto\"", "You're an ok bird."),
                new Line("Winson \"Collecto\"", "We can go again any time, if you'd like.")
            };


            Directions = new List<Direction>
            {
                new Line("Winson \"Collecto\"", "Wow. Just wow. I am very impressed."),
                new Line("Winson \"Collecto\"", "So, about your prize. It's the most prized and valuable thing to my name."),
                new Line("Winson \"Collecto\"", "It's... my respect. You have my respect. Good job guy."),
                new Line("Winson \"Collecto\"", "We can go again any time.")
            };

            if (State.Instance.FailedBeats <= 5 
                && State.Instance.FailedBeats > 2)
            {
                Directions = okDialog;
            }
            else if (State.Instance.FailedBeats <= 2)
            {
                Directions = perfectDialog;
            }
            else
            {
                Directions = lossDialog;
            }

            _animator.CrossFade("Talk", 0f);
            StartCoroutine(StartSequence(() =>
            {
                Directions = DirectionService.Instance.GetDirectionsById(TextId);
                FindObjectOfType<Control>().Disabled = false;
                _animator.CrossFade("Idle", 0f);
            }));
        }
    }
 void Update()
 {
     if (ChangePose)
     {
         print("Change Pose");
         ChangePose = false;
         //if stands
         if (CurrentPose == 0)
         {
             if (Pose == 1)
             {
                 anim.CrossFade("IdleToAggressive", CrossfadeVal);
             }
             else if (Pose == 2)
             {
                 anim.CrossFade("IdleToSit", CrossfadeVal);
             }
             else if (Pose == 3)
             {
                 anim.CrossFade("IdleToLay", CrossfadeVal);
             }
             else if (Pose == 5)
             {
                 anim.CrossFade("IdleToConsume", CrossfadeVal);
             }
             CurrentPose = Pose;
         }
         //aggressive
         else if (CurrentPose == 1)
         {
             if (Pose == 0)
             {
                 anim.CrossFade("AggressiveToIdle", CrossfadeVal);
             }
             else if (Pose == 2)
             {
                 anim.CrossFade("AggressiveToSitTrans", CrossfadeVal);
             }
             else if (Pose == 3)
             {
                 anim.CrossFade("AggressiveToLayTrans", CrossfadeVal);
             }
             else if (Pose == 4)
             {
                 anim.CrossFade("AggressiveToIdle", CrossfadeVal);
             }
             else if (Pose == 5)
             {
                 anim.CrossFade("AggressiveToEat", CrossfadeVal);
             }
             CurrentPose = Pose;
         }
         //Sit
         else if (CurrentPose == 2)
         {
             if (Pose == 0)
             {
                 anim.CrossFade("SitToIdle", CrossfadeVal);
             }
             else if (Pose == 1)
             {
                 anim.CrossFade("SitToAggressiveTrans", CrossfadeVal);
             }
             else if (Pose == 3)
             {
                 anim.CrossFade("SitToLay", CrossfadeVal);
             }
             else if (Pose == 4)
             {
                 anim.CrossFade("SitToIdle", CrossfadeVal);
             }
             else if (Pose == 5)
             {
                 anim.CrossFade("SitToEat", CrossfadeVal);
             }
             CurrentPose = Pose;
         }
         //Lay
         else if (CurrentPose == 3)
         {
             if (Pose == 0)
             {
                 anim.CrossFade("LayToIdle", CrossfadeVal);
             }
             else if (Pose == 1)
             {
                 anim.CrossFade("LayToAggressiveTrans", CrossfadeVal);
             }
             else if (Pose == 2)
             {
                 anim.CrossFade("LayToSit", CrossfadeVal);
             }
             else if (Pose == 4)
             {
                 anim.CrossFade("LayToIdle", CrossfadeVal);
             }
             else if (Pose == 5)
             {
                 anim.CrossFade("LayToEat", CrossfadeVal);
             }
             CurrentPose = Pose;
         }
         //walk or consume
         else if (CurrentPose == 4 || CurrentPose == 5)
         {
             if (Pose == 0)
             {
                 anim.CrossFade("Idle", CrossfadeVal);
             }
             else if (Pose == 1)
             {
                 anim.CrossFade("IdleToAggressive", CrossfadeVal);
             }
             else if (Pose == 2)
             {
                 anim.CrossFade("IdleToSit", CrossfadeVal);
             }
             else if (Pose == 3)
             {
                 anim.CrossFade("IdleToLay", CrossfadeVal);
             }
             else if (Pose == 5)
             {
                 anim.CrossFade("IdleToConsume", CrossfadeVal);
             }
             CurrentPose = Pose;
         }
     }
 }
Esempio n. 44
0
    IEnumerator Walk()
    {
        if (target == null)
        {
            StartCoroutine(Die());
        }
        if (Vector3.Distance(gameObject.transform.position, target.transform.position) >= 1f)
        {
            yield return(new WaitForEndOfFrame());

            if (Physics.Raycast(new Ray(transform.position, -transform.up), 0.9f))
            {
                Vector3 v = target.transform.position;
                v.y = gameObject.transform.position.y;
                gameObject.transform.LookAt(v);
                gameObject.transform.Rotate(new Vector3(0, 90, 0));
                // CC.Move((Suf.transform.position - gameObject.transform.position).normalized * Time.deltaTime * speed);
                transform.position += (target.transform.position - gameObject.transform.position).normalized * Time.deltaTime * speed;
                //gameObject.transform.position += (Suf.transform.position - gameObject.transform.position).normalized * Time.deltaTime * speed;
            }
            else
            {
                AC.CrossFade("Fly", 0f);
            }
            StartCoroutine(Walk());
        }
        else
        {
            GetComponent <AudioSource>().Play();
            RagnarosSubmergeAttack skill = ((Ragnaros)speller).skillManager.GetSkillByName("RagnarosSubmergeAttack") as RagnarosSubmergeAttack;
            skill.Float(((Ragnaros)speller).animator);
            GameObject go = Instantiate(Explosion, null);
            renderer.enabled = false;
            GameObject[] objects = GameController.Register.RightHero.HeroRegister.GetAllGameItems();
            int          num     = 0;
            foreach (GameObject gObject in objects)
            {
                if (gObject.GetComponent <State>() != null)
                {
                    num++;
                }
            }
            float damageVal = 1000 / num;
            if (damageVal > 250)
            {
                damageVal = 250;
            }
            RagnarosDamage damage = new RagnarosDamage(damageVal, DamageType.Fire, gameObject.layer);
            foreach (GameObject gObject in objects)
            {
                if (gObject.GetComponent <State>() != null)
                {
                    gObject.GetComponent <State>().TakeSkillContent(damage);
                }
            }
            go.transform.position = target.transform.position + new Vector3(0, 0.3f, 0);
            go.GetComponent <ParticleSystemMultiplier>().multiplier = 1f;
            yield return(new WaitForSeconds(1.2f));

            DestoryByPool(this);
        }
    }
Esempio n. 45
0
 void testeDeVida(Transform Y,Animator Z)
 {
     float W = Y.GetComponent<umCriature> ().criature ().cAtributos [0].Corrente;
     if(W<=0)
     {
         Z.CrossFade("cair",0);
     }
 }