private void HandleCharacterController()
    {
        //set the speed and acceleration
        float targetVelocity = 0;

        if (this.ParentCharacter.CurrentStance == HumanStances.Crouch)
        {
            if (_isWalkingBack)
            {
                targetVelocity  = 1f;
                _ccAcceleration = 20;
            }
            else
            {
                if (this.ParentCharacter.UpperBodyState == HumanUpperBodyStates.Aim && !this.ParentCharacter.IsHipAiming)
                {
                    targetVelocity  = 1.3f;
                    _ccAcceleration = 10;
                }
                else
                {
                    targetVelocity  = 2f;
                    _ccAcceleration = 10;
                }
            }
        }
        else if (this.ParentCharacter.CurrentStance == HumanStances.Sprint)       //CrouchRun && !_isWalkingBack && !_isStrafing)
        {
            //agent.speed = 2.2f;
            //agent.acceleration = 20;
            UpdateState(HumanBodyStates.WalkForward);
        }



        Vector3 dist = ParentCharacter.Destination.Value - ParentCharacter.transform.position;

        //handle falling



        if (!ParentCharacter.MyCC.isGrounded)
        {
            //ParentCharacter.MyCC.Move(Vector3.zero);
            _ccAirVelocity = _ccAirVelocity + Vector3.down * 19f * Time.fixedDeltaTime;
            _ccVelocity    = _ccVelocity - _ccVelocity * Time.fixedDeltaTime * 3;
            if (_ccVelocity.magnitude < 0.1f)
            {
                _ccVelocity = Vector3.zero;
            }
            ParentCharacter.MyCC.Move((_ccAirVelocity + _ccVelocity) * Time.fixedDeltaTime);
            if (ParentCharacter.MyCC.velocity.magnitude > _highestAirV)
            {
                _highestAirV = ParentCharacter.MyCC.velocity.magnitude;
            }
        }
        else
        {
            //handle non falling
            _ccTargetVelocity = targetVelocity * dist.normalized;
            _ccVelocity       = Vector3.Lerp(_ccVelocity, _ccTargetVelocity, Time.fixedDeltaTime * _ccAcceleration * 0.35f);
            _ccVelocity      += Vector3.down * 19f * Time.fixedDeltaTime;
            ParentCharacter.MyCC.SimpleMove(_ccVelocity);
            //Debug.Log("moving character " + _ccVelocity);
        }

        //handle falling animation
        bool isAlreadyFalling = ParentCharacter.MyAnimator.GetBool("IsAirborne");

        if (!ParentCharacter.MyCC.isGrounded)
        {
            if (!isAlreadyFalling && GameManager.Inst.PlayerControl.GroundDistance > 0.5f)
            {
                if (_airborneTimer < 0.1f)
                {
                    _airborneTimer += Time.fixedDeltaTime;
                }
                else
                {
                    _airborneTimer = 0;
                    ParentCharacter.MyAnimator.SetBool("IsAirborne", true);
                    _ccAirVelocity = Vector3.zero;
                    _ccVelocity    = new Vector3(_ccVelocity.x, 0, _ccVelocity.z);
                    _highestAirV   = 0;
                }
            }
        }
        else
        {
            //handle stop falling
            if (isAlreadyFalling)
            {
                if (_highestAirV > 8f)
                {
                    ParentCharacter.MyAI.BlackBoard.AnimationAction = AnimationActions.HardLanding;
                }
                else
                {
                    ParentCharacter.MyAI.BlackBoard.AnimationAction = AnimationActions.Landing;
                }
                ParentCharacter.MyAI.BlackBoard.ActionMovementDest  = ParentCharacter.transform.position;
                ParentCharacter.MyAI.BlackBoard.ActionMovementSpeed = 0;
                ParentCharacter.SendCommand(CharacterCommands.PlayAnimationAction);

                ParentCharacter.MyAnimator.SetBool("IsAirborne", false);
                ParentCharacter.Destination = ParentCharacter.transform.position;
                ParentCharacter.OnFallLanding(_highestAirV, 8f);
            }
        }

        if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Talk)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.InteractTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 0.8f)
            {
                UpdateState(HumanBodyStates.CrouchIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Talk);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Loot)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.InteractTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 1)
            {
                UpdateState(HumanBodyStates.CrouchIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Loot);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.LootChest)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.UseTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 1)
            {
                UpdateState(HumanBodyStates.CrouchIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.LootChest);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Pickup)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.PickupTarget.transform.position - (this.ParentCharacter.transform.position + new Vector3(0, 0.6f, 0));
            if (targetDist.magnitude <= 1.5f)
            {
                UpdateState(HumanBodyStates.CrouchIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Pickup);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Use)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.UseTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 1.5f)
            {
                UpdateState(HumanBodyStates.StandIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Use);
            }
        }
        else if (dist.magnitude < 0.2f || ParentCharacter.MyCC.velocity.magnitude <= 0.02f)
        {
            UpdateState(HumanBodyStates.CrouchIdle);
        }
    }
    private void HandleCharacterController()
    {
        //set the speed and acceleration
        float targetVelocity = 0;

        if (this.ParentCharacter.CurrentStance == HumanStances.Run || this.ParentCharacter.CurrentStance == HumanStances.Walk || _isWalkingBack)
        {
            if (_isWalkingBack && !_isStrafing)
            {
                if (this.ParentCharacter.UpperBodyState == HumanUpperBodyStates.Aim)
                {
                    //walking backward while aiming
                    targetVelocity = this.ParentCharacter.MyStatus.StrafeSpeed * this.ParentCharacter.MyStatus.StrafeSpeedModifier;
                }
                else
                {
                    if (this.ParentCharacter.GetCurrentAnimWeapon() == WeaponAnimType.Melee)
                    {
                        targetVelocity = this.ParentCharacter.MyStatus.StrafeSpeed * 1.25f;
                    }
                    else
                    {
                        targetVelocity = this.ParentCharacter.MyStatus.WalkSpeed;
                    }
                }

                _ccAcceleration = 20;
            }
            else if (_isStrafing)
            {
                if (this.ParentCharacter.IsHipAiming)
                {
                    targetVelocity = this.ParentCharacter.MyStatus.RunSpeed * this.ParentCharacter.MyStatus.RunSpeedModifier * 0.9f;
                }
                else
                {
                    targetVelocity = this.ParentCharacter.MyStatus.StrafeSpeed * this.ParentCharacter.MyStatus.StrafeSpeedModifier;
                }

                _ccAcceleration = 20;
            }
            else
            {
                if (this.ParentCharacter.CurrentStance == HumanStances.Run)
                {
                    if (this.ParentCharacter.UpperBodyState == HumanUpperBodyStates.Aim)
                    {
                        if (this.ParentCharacter.IsHipAiming)
                        {
                            targetVelocity = this.ParentCharacter.MyStatus.RunSpeed * this.ParentCharacter.MyStatus.RunSpeedModifier * 0.9f;
                        }
                        else
                        {
                            targetVelocity = this.ParentCharacter.MyStatus.StrafeSpeed;
                        }
                    }
                    else
                    {
                        if (this.ParentCharacter.ActionState == HumanActionStates.Melee)
                        {
                            targetVelocity = this.ParentCharacter.MyStatus.WalkSpeed;
                        }
                        else
                        {
                            targetVelocity = this.ParentCharacter.MyStatus.RunSpeed * this.ParentCharacter.MyStatus.RunSpeedModifier;
                        }
                    }
                    _ccAcceleration = 20;
                }
                else
                {
                    targetVelocity  = this.ParentCharacter.MyStatus.WalkSpeed;
                    _ccAcceleration = 10;
                }
            }
        }
        else if (this.ParentCharacter.CurrentStance == HumanStances.Sprint && !_isWalkingBack)
        {
            targetVelocity  = this.ParentCharacter.MyStatus.SprintSpeed * this.ParentCharacter.MyStatus.SprintSpeedModifier;
            _ccAcceleration = 20;
        }

        if (this.ParentCharacter.IsBodyLocked || this.ParentCharacter.IsMoveLocked)
        {
            UpdateState(HumanBodyStates.StandIdle);
        }

        Vector3 dist = ParentCharacter.Destination.Value - ParentCharacter.transform.position;

        //handle falling

        if (!ParentCharacter.MyCC.isGrounded)
        {
            //ParentCharacter.MyCC.Move(Vector3.zero);
            _ccAirVelocity = _ccAirVelocity + Vector3.down * 19f * Time.fixedDeltaTime;
            _ccVelocity    = _ccVelocity - _ccVelocity * Time.fixedDeltaTime * 3;
            if (_ccVelocity.magnitude < 0.1f)
            {
                _ccVelocity = Vector3.zero;
            }
            ParentCharacter.MyCC.Move((_ccAirVelocity + _ccVelocity) * Time.fixedDeltaTime);
            if (ParentCharacter.MyCC.velocity.magnitude > _highestAirV)
            {
                _highestAirV = ParentCharacter.MyCC.velocity.magnitude;
            }
        }
        else
        {
            //handle non falling
            _ccTargetVelocity = targetVelocity * dist.normalized;
            _ccVelocity       = Vector3.Lerp(_ccVelocity, _ccTargetVelocity, Time.fixedDeltaTime * _ccAcceleration * 0.35f);
            _ccVelocity      += Vector3.down * 19f * Time.fixedDeltaTime;
            ParentCharacter.MyCC.Move(_ccVelocity * Time.fixedDeltaTime);
        }

        //handle falling animation
        bool isAlreadyFalling = ParentCharacter.MyAnimator.GetBool("IsAirborne");

        if (!ParentCharacter.MyCC.isGrounded)
        {
            if (!isAlreadyFalling && GameManager.Inst.PlayerControl.GroundDistance > 0.5f)
            {
                if (_airborneTimer < 0.1f)
                {
                    _airborneTimer += Time.fixedDeltaTime;
                }
                else
                {
                    _airborneTimer = 0;
                    ParentCharacter.MyAnimator.SetBool("IsAirborne", true);
                    _ccAirVelocity = Vector3.zero;
                    _ccVelocity    = new Vector3(_ccVelocity.x, 0, _ccVelocity.z);
                    _highestAirV   = 0;
                }
            }
        }
        else
        {
            //handle stop falling
            if (isAlreadyFalling)
            {
                if (_highestAirV > 8f)
                {
                    ParentCharacter.MyAI.BlackBoard.AnimationAction = AnimationActions.HardLanding;
                }
                else
                {
                    ParentCharacter.MyAI.BlackBoard.AnimationAction = AnimationActions.Landing;
                }
                ParentCharacter.MyAI.BlackBoard.ActionMovementDest  = ParentCharacter.transform.position;
                ParentCharacter.MyAI.BlackBoard.ActionMovementSpeed = 0;
                ParentCharacter.SendCommand(CharacterCommands.PlayAnimationAction);

                ParentCharacter.MyAnimator.SetBool("IsAirborne", false);
                ParentCharacter.Destination = ParentCharacter.transform.position;
                ParentCharacter.OnFallLanding(_highestAirV, 8f);
            }
        }

        if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Talk)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.InteractTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 1.5f)
            {
                UpdateState(HumanBodyStates.StandIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Talk);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Loot)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.InteractTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 1)
            {
                UpdateState(HumanBodyStates.StandIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Loot);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.LootChest)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.UseTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 1)
            {
                UpdateState(HumanBodyStates.StandIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.LootChest);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Pickup)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.PickupTarget.transform.position - (this.ParentCharacter.transform.position + new Vector3(0, 0.6f, 0));
            if (targetDist.magnitude <= 1.5f)
            {
                UpdateState(HumanBodyStates.StandIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Pickup);
            }
        }
        else if (this.ParentCharacter.MyAI.BlackBoard.PendingCommand == CharacterCommands.Use)
        {
            Vector3 targetDist = this.ParentCharacter.MyAI.BlackBoard.UseTarget.transform.position - this.ParentCharacter.transform.position;
            if (targetDist.magnitude <= 1.5f)
            {
                UpdateState(HumanBodyStates.StandIdle);
                this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
                this.ParentCharacter.SendCommand(CharacterCommands.Use);
            }
        }



        if (dist.magnitude < 0.2f || ParentCharacter.MyCC.velocity.magnitude <= 0.02f)
        {
            this.ParentCharacter.MyAI.BlackBoard.PendingCommand = CharacterCommands.Idle;
            UpdateState(HumanBodyStates.StandIdle);
        }
    }