Hi,
i have some units in a formation (RTS-Like). The formation is dynamic (or at least the goal is that it is dynamic). If there is an obstacle, the formation changes so every unit can receive a valid destination.
My AI is using a simple Behavior Tree: only a Wait node and a Move-To. If the Destination changes, a Sequence triggers the Move To node.
To test if the desired destination is valid, I’m using UNavigationSystem::TestPathSync. But it seems like this is not bringing up correct results.
In the attached picture is my setup: The two red-circles are marking the destination. As you can see, even if the destination of the second unit (the red line) is right inside the wall, the function returns “true” (the green message). I have to move the destination a little bit further into the wall before the function return false. Of course the unit is not moving if the red circle is touching the wall (the Move To node just returns “Failed”)
This is the code that I’m using:
bool ABaseAIController::TestIfDestinationIsReachable(FVector TestDestination)
{
UNavigationSystem* NavSystem = GetWorld()->GetNavigationSystem();
if (NavSystem)
{
FVector LineStart = TestDestination;
FVector LineEnd = TestDestination;
LineStart.Z = -200.f;
LineEnd.Z = 200.f;
DrawDebugLine(GetWorld(), LineStart, LineEnd, FColor::Red, false, 0.1f, 1, 5.f);
FPathFindingQuery QueryParams;
QueryParams.StartLocation = GetPawn()->GetActorLocation();
QueryParams.EndLocation = TestDestination;
QueryParams.NavData = NavSystem->GetMainNavData();
QueryParams.Owner = this;
QueryParams.SetAllowPartialPaths(false);
return NavSystem->TestPathSync(QueryParams, EPathFindingMode::Hierarchical);
}
return false;
}
Am I doing something wrong or is there another issue?