Prototype/Source/Prototype/Private/Task_ObstAvoid.cpp
/* Look for obstacles in the given direction. Sets the agent status to avoiding if an obstacle is detected.
*  Returns array of "safe" vectors.
*
*   @return Array of obstacle-free vectors.
*/
Look for obstacles in the given direction. Sets the agent status to avoiding if an obstacle is detected.
Returns array of "safe" vectors.

@return Array of obstacle-free vectors.
Look for obstacles in the given direction . Sets the agent status to avoiding if an obstacle is detected . Returns array of " safe " vectors . @return Array of obstacle - free vectors .
TArray<FVector> AUSARAgent::LookAhead(FVector vel, bool& obstructed)
{
    FVector agentLoc = GetActorLocation();
    FVector targetVector = vel.GetClampedToSize(0, OBSTACLE_AVOID_DIST);
    FRotator velRot = vel.Rotation();
    targetVector = TransformToWorld(targetVector);
    TArray<FVector> rayStartPts;
    rayStartPts.Add(agentLoc);
    TArray<FVector> rayEndPts;
    rayEndPts.Add(targetVector);
    float degStep = 45;  
    for (int circle = BODY_SIZE; circle <= BODY_SIZE; circle += 5) {
        FVector offset = FVector(0, circle, 0);
        for (float deg = 0; deg < 360; deg += degStep) {
            FRotator rotRoll = FRotator(0, 0, deg);
            offset = rotRoll.RotateVector(offset);
            offset = velRot.RotateVector(offset);
            rayStartPts.Add(agentLoc + offset);
            rayEndPts.Add(targetVector + offset);
            deg += degStep;
            if (showDebug) {
                if (circle == BODY_SIZE) {
                    DrawDebugLine(GetWorld(), agentLoc + offset, targetVector + offset, FColor::Orange, false, RATE_AVOID_TASK, 2.5);
                }
            }
        }
    }
    FHitResult hitResult;
    FCollisionObjectQueryParams objectParams;
    objectParams.AddObjectTypesToQuery(ECC_WorldStatic);
    FCollisionQueryParams queryParams;
    queryParams.AddIgnoredActor(this);
    TArray<FVector> safeVectors;
    for (int i = 0; i < rayStartPts.Num(); i++) {
        if(!GetWorld()->LineTraceSingleByObjectType(hitResult, rayStartPts[i], rayEndPts[i], objectParams, queryParams)) {
            safeVectors.Add(rayEndPts[i]);
        }
        else {
            obstructed = true;
            if (showDebug) {
                DrawDebugPoint(GetWorld(), hitResult.ImpactPoint, 3, FColor::Red, false, 0.01);
            }
        }
    }
    return safeVectors;
}
TArray < FVector > AUSARAgent :: LookAhead ( FVector vel , bool & obstructed ) { FVector agentLoc = GetActorLocation ( ) ; FVector targetVector = vel . GetClampedToSize ( 0 , OBSTACLE_AVOID_DIST ) ; FRotator velRot = vel . Rotation ( ) ; targetVector = TransformToWorld ( targetVector ) ; TArray < FVector > rayStartPts ; rayStartPts . Add ( agentLoc ) ; TArray < FVector > rayEndPts ; rayEndPts . Add ( targetVector ) ; float degStep = 45 ; for ( int circle = BODY_SIZE ; circle <= BODY_SIZE ; circle += 5 ) { FVector offset = FVector ( 0 , circle , 0 ) ; for ( float deg = 0 ; deg < 360 ; deg += degStep ) { FRotator rotRoll = FRotator ( 0 , 0 , deg ) ; offset = rotRoll . RotateVector ( offset ) ; offset = velRot . RotateVector ( offset ) ; rayStartPts . Add ( agentLoc + offset ) ; rayEndPts . Add ( targetVector + offset ) ; deg += degStep ; if ( showDebug ) { if ( circle == BODY_SIZE ) { DrawDebugLine ( GetWorld ( ) , agentLoc + offset , targetVector + offset , FColor :: Orange , false , RATE_AVOID_TASK , 2.5 ) ; } } } } FHitResult hitResult ; FCollisionObjectQueryParams objectParams ; objectParams . AddObjectTypesToQuery ( ECC_WorldStatic ) ; FCollisionQueryParams queryParams ; queryParams . AddIgnoredActor ( this ) ; TArray < FVector > safeVectors ; for ( int i = 0 ; i < rayStartPts . Num ( ) ; i ++ ) { if ( ! GetWorld ( ) -> LineTraceSingleByObjectType ( hitResult , rayStartPts [ i ] , rayEndPts [ i ] , objectParams , queryParams ) ) { safeVectors . Add ( rayEndPts [ i ] ) ; } else { obstructed = true ; if ( showDebug ) { DrawDebugPoint ( GetWorld ( ) , hitResult . ImpactPoint , 3 , FColor :: Red , false , 0.01 ) ; } } } return safeVectors ; }
Look for obstacles in the given direction.
Look for obstacles in the given direction .
// Transform agent velocity from local to world coordinates // Create array of raycast start/end points in concentric circles around agent // decrease to increase fidelity of raycast cylinders. recommend factor of 360 /*DEBUGGING*/ /*DEBUGGING*/ // collect vectors with no obstacles. /*DEBUGGING*/ /*DEBUGGING*/