Hello. It seems to be my AI is not generating Path properly. I’ve overriden FollowPathSegment and i Inherited to UPathFollowingComponent. So i can put my root motion controller in my AI.
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();
FVector diff = (currentTarget - currentLocation).GetSafeNormal();
float dotForward = FVector::DotProduct(currentForward, diff);
float dotRight = FVector::DotProduct(currentRight, diff);
FVector cur = currentLocation;
for (auto &i : Path->GetPathPoints())
{
UKismetSystemLibrary::DrawDebugArrow(GetWorld(), cur, i.Location, 20.0f, FLinearColor::Green, 0.0f, 20);
cur = i.Location;
}
PawnReference->MoveForward(dotForward);
PawnReference->MoveRight(dotRight);
const int32 LastSegmentStartIndex = Path->GetPathPoints().Num() - 2;
MovementComp->RequestDirectMove((currentTarget - currentLocation) / DeltaTime, MoveSegmentStartIndex < LastSegmentStartIndex);
PostProcessMove.ExecuteIfBound(this, diff);
}
Please help I’ve been stuck for days. The navmesh is already baked.