void MoveCharacterWithNavmesh()
    {
        Vector3 rawMoveDir = Vector3.forward * vertical + Vector3.right * horizontal;

        Vector3    cameraForwardNormalized = Vector3.ProjectOnPlane(currentCamera.forward, Vector3.up);
        Quaternion rotationToCamNormal     = Quaternion.LookRotation(cameraForwardNormalized, Vector3.up);

        Vector3 finalMoveDir = rotationToCamNormal * rawMoveDir;

        moving = false;
        if (!Vector3.Equals(finalMoveDir, Vector3.zero))
        {
            Quaternion rotationToMoveDir = Quaternion.LookRotation(finalMoveDir, Vector3.up);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationToMoveDir, rotationSpeed * Time.deltaTime);
            moving             = true;
        }

        if (moving && _soundManager.EffectSounds[EffectSound.Running])
        {
            _soundManager.StartSound(_soundManager.EffectSounds[EffectSound.Running]);
        }
        else if (_soundManager.EffectSounds[EffectSound.Running])
        {
            _soundManager.StopSound(_soundManager.EffectSounds[EffectSound.Running]);
        }


        animator.SetBool("Moving", moving);
        animator.SetFloat("VerticalSpeed", vertical);

        Vector3 result = finalMoveDir * (isSprinting ? moveSpeed * 2 : moveSpeed) * Time.deltaTime;

        navMeshAgent.Move(result);
    }
 private void CheckMovement()
 {
     if (!lastTargetVisited)
     {
         if (trigger)
         {
             GoTo(currentTarget);
             trigger = false;
             if (targetQueue.Count > 0)
             {
                 currentTarget = targetQueue.Dequeue();
             }
         }
     }
     if (navMeshAgent.remainingDistance < navMeshAgent.stoppingDistance)
     {
         isMoving = false;
     }
     else
     {
         isMoving = true;
     }
     if (isMoving)
     {
         animator.SetBool("NPC Walking", true);
         if (_soundManager.EffectSounds.ContainsKey(EffectSound.Walking))
         {
             _soundManager.StartSound(_soundManager.EffectSounds[EffectSound.Walking]);
         }
     }
     else
     {
         animator.SetBool("NPC Walking", false);
         if (_soundManager.EffectSounds.ContainsKey(EffectSound.Walking))
         {
             _soundManager.StopSound(_soundManager.EffectSounds[EffectSound.Walking]);
         }
     }
 }
 private void FixedUpdate()
 {
     if (!_npcMovement.IsMoving && _canBeChecked)
     {
         MyMovementType = MovementType.ControlledMove;
         _canBeChecked  = false;
     }
     if (MyMovementType == MovementType.AutoMove && _movementTypeChanged)
     {
         _complexMove.enabled = false;
         _npcMovement.enabled = true;
         _npcMovement.MoveNextPosition();
         _movementTypeChanged = false;
     }
     if (MyMovementType == MovementType.ControlledMove && _movementTypeChanged)
     {
         _npcMovement.GetComponent <NavMeshAgent>().ResetPath();
         _soundManager.StopSound(_soundManager.EffectSounds[EffectSound.Walking]);
         _npcMovement.enabled = false;
         _npcMovement.TargetQueue.Clear();
         _complexMove.enabled = true;
         _movementTypeChanged = false;
     }
 }