Hello. I do RTS and have one problem. When a squad goes around an obstacle, it stacks up at one point. Theoretically I know how to get around the problem. It is necessary to use eqs to check each point of the path for obstacles and set the offset for all members of the squads. But I don’t know how to change the pre-calculated path.
The way it works now
ABaseSquad class
void ABaseSquad::MoveTo(FVector Goal, FRotator Rotation)
{
UHungarianHelper* Helper = NewObject<UHungarianHelper>();
std::vector<std::vector<int>> DistMatrix;
std::vector<int> TargetPoint;
FString test1;
for (int i = 0; i < Characters.Num(); i++)
{
std::vector<int> Row;
for (int j = 0; j < Indicators.Num(); j++)
{
Row.push_back(Characters[i]->GetDistanceTo(Indicators[j]));
}
DistMatrix.push_back(Row);
}
Helper->Solve(DistMatrix, TargetPoint);
for (int i = 0; i < Characters.Num(); i++)
{
Characters[i]->MoveTo(Indicators[TargetPoint[i]]->GetActorLocation(), Indicators[TargetPoint[i]]->GetActorRotation());
}
Pathfinder->FindPathAndMove(Goal, nullptr, Rotation);
}
PathfinderComponent class
void UPathfinderComponent::FindPathAndMove(FVector Goal, AActor* GoalActor, FRotator Rotation)
{
ACharacter* OwnerChar = Cast<ACharacter>(GetOwner());
if (!IsValid(OwnerChar))
{
return;
}
UNavigationPath* Path;
if (IsValid(GoalActor))
{
Path = UNavigationSystemV1::FindPathToActorSynchronously(this, OwnerChar->GetActorLocation(), GoalActor, 5, OwnerChar);;
} else
{
Path = UNavigationSystemV1::FindPathToLocationSynchronously(this, OwnerChar->GetActorLocation(), Goal, OwnerChar);;
}
Path->EnableDebugDrawing(true, FColor::Black);
if (Path && Path->IsValid())
{
TArray<FNavPathPoint> Points = Path->GetPath()->GetPathPoints();
for (int i = 1; i < Points.Num(); i++)
{
DrawDebugLine(GetWorld(), Points[i - 1].Location, Points[i].Location, FColor::Green, true);
}
FAIMoveRequest req;
req.SetAcceptanceRadius(1);
req.SetUsePathfinding(true);
auto Test = Path->GetPath();
AUnitAIController* ai = OwnerChar->GetController<AUnitAIController>();
if (ai)
{
ai->SetRotator(Rotation);
ai->RequestMove(req, Path->GetPath());
}
}
}
Bad Path (now work)
Good Path (that’s what I want)