Hi. I’m having some difficulties using mp.chosenTarget from OnPathComplete() using MultiTargetPath, but here is some context.
I have read on this forum that for improving combat when you have more enemies I could try having spots around player. So I’ve started implementing this approach.
-
The first thing was to spawn spots around agents. Script Example (maybe will be helpful for someone)
-
I have an EnemiesManager gameobject which has both Seeker and a FunnelModifier components attached. My thoughts on this class is to have a manager which handles on which spots enemies should go.
So I’m using this coroutine and “_spots.GetFreeSpotPositions()” returns an array with unmarked targets(positions).
private IEnumerator StartMultiTargetPath()
{
for (int i = 0; i < _enemies.Count; i++)
{
var enemy = _enemies[i];
if (_spots != null)
{
// wait in order to mark "i-1" found spot as occupied when seeker.IsDone()
yield return new WaitUntil(() => _seeker.IsDone());
MultiTargetPath path = MultiTargetPath.Construct(enemy.Position, _spots.GetFreeSpotPositions(), null, null);
path.pathsForAll = false;
_seeker.StartPath(path, OnPathComplete);
yield return StartCoroutine(path.WaitForPath());
_seeker.PostProcess(path);
}
}
}
On OnPathComplete I’m using most of documentation code for debub draw plus a method which marks that closest spot as occupied.
private void HandleChosenTarget(int index)
{
if (index == -1)
{
Debug.LogError("Found no closest target.");
return;
}
Debug.Log("ChosenTarget: " + index);
var targetSpot = _spots.GetSpotTarget(index);
targetSpot.SetOccupied(true);
}
_spots.GetSpotTarget - returns a reference based on index.
So here comes my problem:
public Vector3[] GetFreeSpotPositions()
{
Vector3[] spotPositions = new Vector3[surroundingTargets.Count];
for(int i = 0; i < surroundingTargets.Count; i++)
{
var spot = surroundingTargets[i];
if (spot.IsOccupied)
{
continue;
}
spotPositions[i] = spot.Target.position;
}
return spotPositions;
}
In StartMultiTargetPath() coroutine on first call, every enemy will get his closest spot. But what should I do on second/third etc call of the coroutine in order to have mp.chosenTarget index matching my default target positions array not just the unmarked positions?