Prototype/Source/Prototype/Private/Task_Flock.cpp
/**
*   Calculate center of mass of neighbors relative to agent.
*
*   @param agent Agent to calculate cohesion vector for.
*   @return Vector pointing to center mass of agent's neighbors. Returns zero if agent has no neighbors.
*/
Calculate center of mass of neighbors relative to agent.
Calculate center of mass of neighbors relative to agent .
FVector AUSARAgent::GetCohesion()
{
    float fSize = static_cast<float>(flockSize);
    FVector centerMass = FVector::ZeroVector;
    for (AUSARAgent* boid : neighborAgents) {
        centerMass += boid->GetActorLocation();
    }
    flockCenter = centerMass + GetActorLocation();
    flockCenter /= fSize;
    centerMass /= fSize - 1;
    centerMass -= GetActorLocation();
    if (showDebug) {
        DrawDebugPoint(GetWorld(), flockCenter, 25, FColor::Purple, false, RATE_FLOCK_TASK);
    }
    return centerMass;
}
FVector AUSARAgent :: GetCohesion ( ) { float fSize = static_cast < float > ( flockSize ) ; FVector centerMass = FVector :: ZeroVector ; for ( AUSARAgent * boid : neighborAgents ) { centerMass += boid -> GetActorLocation ( ) ; } flockCenter = centerMass + GetActorLocation ( ) ; flockCenter /= fSize ; centerMass /= fSize - 1 ; centerMass -= GetActorLocation ( ) ; if ( showDebug ) { DrawDebugPoint ( GetWorld ( ) , flockCenter , 25 , FColor :: Purple , false , RATE_FLOCK_TASK ) ; } return centerMass ; }
Calculate center of mass of neighbors relative to agent.
Calculate center of mass of neighbors relative to agent .
/*DEBUGGING*/ /*DEBUGGING*/