RTS Unit Not Moving to the exact location sometimes in ue5

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 :frowning:

Hi and Welcome to the community,

This site is really for support of the Gamedev courses and so we don’t usually help out with projects. You can try the official forums or possibly take a look at the unreal source discord (Unreal Source)

Sorry I can’t be of more help

Oh Sorry, I didn’t know that… I had asked questions before in this site , but it must have been the official forum You are talking about.
it’s Ok You are right! I’m gonna find the right forum and post there thx.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms