Hey I’m trying to build an RTS prototype and I have a weird issue with forming a formation with units. the units sometimes move to the correct position and sometimes not exactly and they stop their movement in an offset. (usually the first time fails and the subsequent attempts work just fine on a button click). I’m stuck at this for like a week… I’m pasting the codes related to the RectangularFormation but I have the same issue with linear and triangular Formation as well.
this is the calculation for rectangleFormation:
TArray<FVector> ARTS_PlayerController::CalculateRectangularFormation(int numUnits, int unitsPerRow, float unitSpacing, const FVector& Origin)
{
ensure(unitsPerRow != 0);
TArray<FVector> Positions;
Positions.Reserve(numUnits);
int row;
int col;
for (int i = 0; i < numUnits; ++i)
{
row = i / unitsPerRow;
col = i % unitsPerRow;
//
float unitX = col * unitSpacing;
float unitY = row * unitSpacing;
Positions.Emplace(FVector(unitX, unitY, 0.0f) + Origin);
}
return Positions;
}
and this is how I’m moving the units around:
UAIBlueprintHelperLibrary::SimpleMoveToLocation(SpawnedSoldier->GetController(), GoalLocation);
this is a photo of when they haven’t moved to the exact location:
and this is how they should be:
I’ve confirmed that the Positions that the CalculateRectangularFormation returns are indeed forming a rectangle. I feel like the problem is with the AIController or navigation or sth… but I dunno what to do…
I’m using the default AIController class for these units. I also tried creating an AIController myself and playing with some default values but no luck