Hello! I overrided the UPathFollowingComponent for root motion capabilities but I encountered a problem where when the AI pawn arrived in a segment along the path he suddenly stops for a few second then move again. It’s very weird since I did not write any wait command.
Thank you for helping me!
Here is my code:
void URootMotionPathFollowing::FollowPathSegment(float deltaTime)
{
if(!Path.IsValid() || PawnReference == nullptr)
return;
const FVector currentLocation = MovementComp->GetActorFeetLocation();
const FVector currentTarget = GetCurrentTargetLocation();
const FRotator currentRotation = PawnReference->GetActorRotation();
const FVector currentForward = UKismetMathLibrary::GetForwardVector(currentRotation).GetSafeNormal();
const FVector currentRight = UKismetMathLibrary::GetRightVector(currentRotation).GetSafeNormal();
const FRotator delta = UKismetMathLibrary::FindLookAtRotation(currentLocation, currentTarget);
FRotator newRot = FMath::RInterpTo(currentRotation, delta, deltaTime,TurnSpeed);
newRot.Pitch = 0;
newRot.Roll = 0;
PawnReference->SetActorRotation(newRot);
const FVector diff = UKismetMathLibrary::Normal((currentTarget - currentLocation), 0.0001);
float dotForward = FVector::DotProduct(currentForward, diff);
float dotRight = FVector::DotProduct(currentRight, diff);
dotForward = FMath::Abs(dotForward) > VerticalCeil ? dotForward < 0? -1 : 1 : dotForward;
dotRight = FMath::Abs(dotRight) > HorizontalCeil ? dotForward < 0 ? -1 : 1 : dotRight;
PawnReference->MoveForward(dotForward);
PawnReference->MoveRight(dotRight);
Super::FollowPathSegment(deltaTime);
}