Exemple #1
0
    private void UpdateTarget(Vector3?targetPosition = null)
    {
        _targetPosition = targetPosition.HasValue ? targetPosition.Value : SearchNextTarget();

        var targetCellPosition = _aiManager.CellPosition(_targetPosition);
        var origin             = _aiManager.CellPosition(transform.position);

        _currentPath = _aiManager.ComputePath(origin, targetCellPosition);

        OnCostMapChanged?.Invoke(_player);

        if (_currentPath.Count == 0)
        {
            Debug.LogWarning("No way to reach the target !");
            return;
        }

        _nextPosition     = _aiManager.WorldPosition(_currentPath.Pop());
        _isMovingToTarget = true;

        OnPathChanged?.Invoke(_player);
    }