Attach AI Sight to Pawn Head? (Perception)

Here’s the function that determines the Sense’s orientation (from AIPerceptionComponent.cpp)


void UAIPerceptionComponent::GetLocationAndDirection(FVector& Location, FVector& Direction) const
{
    const AActor* OwnerActor = Cast<AActor>(GetOuter());
    if (OwnerActor != nullptr)
    {
        FRotator ViewRotation(ForceInitToZero);
        OwnerActor->GetActorEyesViewPoint(Location, ViewRotation);
        Direction = ViewRotation.Vector();
    }
}


Thankfully AActor::GetActorEyesViewPoint is a virtual function, so you can override it for your pawn, but only in c++.

5 Likes