I’m definitely not against them. I’m just not sure that whatever issue I have that makes the flawed first part of the cross-floor pathfinding work as it does in the lesson might impact the following steps and I’d rather squish it soonest rather than hatching it and having even more difficulties in tracking it down.
Since all that GetNeighbourList()
does is taking in one pathnode and collecting all nodes thar are adjacent in all directions without doing any logical selection except dropping all potential neighbours that actually don’t exist because they’re outside the grids’ bounds, this information should be static throughout the game.
Thus running through all pathnodes once to gather this information and handing the cached list back (or rather a clone of it) should certainly speed up the pathfinding calculations quite a bit.
OTOH it won’t change any semantics so while I should make that change, it won’t help squishing the bug…
Debug.Log($"Total neighbours before: n-count: {neighbourList.Count} total-count: {totalNeighbourList.Count}");
So I get the same 8 neighbours around the unit on the same floor.
Debug.Log($"Total neighbours after: {totalNeighbourList.Count}");
This is when all neighbouring “above” and “below” nodes are added to the totalNeighbourList
.
When this output is activated, I also get “Total neighbours after culling: 16
”, so the 8 potential grid nodes on floor 2 (which doesn’t exist) get thrown out.
GetNeighbourList()
appears to be correct, so my next guess would be that within the MoveAction
inside of GetValidActionGridPositionList()
some are sorted out as invalid, that shouldnt…
In particular…
for (int x = -_maxMoveDistance; x <= _maxMoveDistance; x++)
{
for (int z = -_maxMoveDistance; z <= _maxMoveDistance; z++)
{
//for (int floor = 0; floor <= _maxMoveDistance; floor++)
for (int floor = 0; floor < LevelGrid.Instance.FloorAmount; floor++)
{
GridPosition offsetGridPosition = new GridPosition(x, z, floor);
GridPosition testGridPosition = unitGridPosition + offsetGridPosition;
// Is the test position within the bounds of the grid?
if (!LevelGrid.Instance.IsValidGridPosition(testGridPosition)) continue;
So… We take a subset of the grid around the unit limited by the maxMoveDistance
, and for each position we then go through all floors…
unit at (ux,uz, floor==0)
loop floor 0: offset is (x,z, 0) → testGridPosition is (ux+x, uz+z, 0)
loop floor 1: offset is (x,z, 1) → testGridPosition is (ux+x, uz+z, 1)
So this should still be a valid grid position and my debug-rays do show rays going from the unit on floor 0 going up to floor 1 positions in its range…
For some reason they don’t get to be valid target positions though…
unit at (ux,uz, floor==1)
loop floor 0: offset is (x,z, 0) → testGridPosition is (ux+x, uz+z, 1)
loop floor 1: offset is (x,z, 1) → testGridPosition is (ux+x, uz+z, 2)
This looks like there is an issue, right here. Setting the testPosition’s floor
to the loop floor is fine, but we can’t allow using the unit’s floor
value at this point…
This would explain why no rays go from the floor-1 unit down to floor 0.
Let’s fix it, and go on…
GridPosition offsetGridPosition = new GridPosition(x, z, 0);
GridPosition testGridPosition = unitGridPosition + offsetGridPosition;
testGridPosition.floor = floor;
And suddenly there are rays going from the floor-1 unit down to floor 0, as there should be.