Prototype/Source/Prototype/Private/Task_Flock.cpp
/**
*   Calculate negative direction to neighbors for agent. Closer neighbors provide greater impetus.
*
*   @param agent Agent to calculate separation vector for.
*   @return Vector pointing away from neighbors.
*/
Calculate negative direction to neighbors for agent. Closer neighbors provide greater impetus.
Calculate negative direction to neighbors for agent . Closer neighbors provide greater impetus .
FVector AUSARAgent::GetSeparation()
{
    FVector sepDir = FVector::ZeroVector;
    TArray<AUSARAgent*> neighbors = GetNeighbors();
    FVector agentLoc = GetActorLocation();
    FVector boidLoc, separation;
    for (AUSARAgent* n : neighbors) {
        if (n) {
            boidLoc = n->GetActorLocation();
            separation = agentLoc - boidLoc;
            float sepFactor = 0;
            float dist = separation.Size();
            float spacing = agentSpacing;
            if (dist < spacing) {
                sepFactor = -5 * (FMath::Loge(dist) - FMath::Loge(agentSpacing));
            }
            sepDir += sepFactor * separation;
        }
    }
    sepVector = sepDir;
    return sepDir;
}
FVector AUSARAgent :: GetSeparation ( ) { FVector sepDir = FVector :: ZeroVector ; TArray < AUSARAgent * > neighbors = GetNeighbors ( ) ; FVector agentLoc = GetActorLocation ( ) ; FVector boidLoc , separation ; for ( AUSARAgent * n : neighbors ) { if ( n ) { boidLoc = n -> GetActorLocation ( ) ; separation = agentLoc - boidLoc ; float sepFactor = 0 ; float dist = separation . Size ( ) ; float spacing = agentSpacing ; if ( dist < spacing ) { sepFactor = -5 * ( FMath :: Loge ( dist ) - FMath :: Loge ( agentSpacing ) ) ; } sepDir += sepFactor * separation ; } } sepVector = sepDir ; return sepDir ; }
Calculate negative direction to neighbors for agent.
Calculate negative direction to neighbors for agent .
/*DEBUGGING*/ //if (agent->showDebug) { //    FString sepText = FString::Printf(TEXT("Agent %d->%d sepFactor = %f (%f)."), agent->agentID, n->agentID, sepFactor, dist); //    GEngine->AddOnScreenDebugMessage(INDEX_NONE, 10.0f, FColor::Yellow, sepText, true); //} /*DEBUGGING*/ /*DEBUGGING*/ /*DEBUGGING*/