I’ve noticed what would seem to me as incorrect behavior from the AI Prediction Sense when trying to predict an actor/pawn that is inheriting velocity from an attach parent:
UAISense_Prediction::Update
expectedly uses GetVelocity()
to get the velocity of the predicted actor and calculate where it will be in the specified amount of time:
const FVector PredictedLocation = Event.PredictedActor->GetActorLocation() + Event.PredictedActor->GetVelocity() * Event.TimeToPredict;
However, if we take a look at AActor::GetVelocity
and APawn::GetVelocity
we see this:
FVector AActor::GetVelocity() const
{
if ( RootComponent )
{
return RootComponent->GetComponentVelocity();
}
return FVector::ZeroVector;
}
FVector APawn::GetVelocity() const
{
if(GetRootComponent() && GetRootComponent()->IsSimulatingPhysics())
{
return GetRootComponent()->GetComponentVelocity();
}
const UPawnMovementComponent* MovementComponent = GetMovementComponent();
return MovementComponent ? MovementComponent->Velocity : FVector::ZeroVector;
}
These both just get velocity of components, which I believe is represented relative to the actor’s frame of reference. I have only tested this with a pawn using a movement component, and can verify that MovementComponent->Velocity
is in local terms for the pawn, which means that prediction will be inaccurate for any such pawn attached to another actor that also has velocity.
There are ways I can work around this for my own purposes, but the question I’m posing to the community here is, should this be considered a bug / incorrect behavior? Specifically from the perspective of UAISense_Prediction
- there is a separate philosophical discussion that could be had on whether and how global velocity should be made available - but with respect to the actual purpose of the prediction sense itself, I feel like this behavior is not correct.
The way I see it, prediction is intended to determine where an actor will be in X amount of time based on their location and velocity - in world space. Location is naturally understood to be passed as world space, or else the predictions would not be very useful. Shouldn’t it be similarly important that we also consider the total velocity of the actor in this calculation?
Of course, what that would ultimately have to look like is walking up the attachment chain and adding every parent actor’s velocity to the total value. I admittedly don’t have any context around the original work here, so maybe there is an established reason I am missing for why this is not such a simple thing to do. But, I thought it was rather curious, and I couldn’t find any previous discussion by searching the forums here, so figured I would ask what people think.
What’s your take?