Prototype/Source/Prototype/Private/Task_Flock.cpp
/**
*   Calculate average velocity of neighbors for agent.
*
*   @param agent Agent to calculate alignment vector for.
*   @return Average velocity of neighbors. Returns zero if agent has no neighbors.
*/
Calculate average velocity of neighbors for agent.
Calculate average velocity of neighbors for agent .
FVector AUSARAgent::GetAlignment()
{
    FVector alVec = FVector::ZeroVector;
    TArray<AUSARAgent*> neighbors = GetNeighbors();
    for (AUSARAgent* boid : neighbors) {
        if (boid) {
            alVec += boid->GetVelocity();
        }
    }
    alVec /= neighbors.Num();
    alignVector = alVec;
    return alVec;
}
FVector AUSARAgent :: GetAlignment ( ) { FVector alVec = FVector :: ZeroVector ; TArray < AUSARAgent * > neighbors = GetNeighbors ( ) ; for ( AUSARAgent * boid : neighbors ) { if ( boid ) { alVec += boid -> GetVelocity ( ) ; } } alVec /= neighbors . Num ( ) ; alignVector = alVec ; return alVec ; }
Calculate average velocity of neighbors for agent.
Calculate average velocity of neighbors for agent .
/*DEBUGGING*/ /*DEBUGGING*/