Normally, Prediction sense works quite well, but it stops working whenever the character jumps. The reason is probably that it detects the PredictedLocation at a point that’s quite far below and outside the NavMesh bounds. To solve this, I tried using the ProjectPointToNavigation function, and i even added an extra value to the Z-axis, hoping it might help, but it still didn’t work. How to solve this problem?
Here is the first code:
if (Stimulus.Type == SensePredictionID)
{
if (Stimulus.WasSuccessfullySensed())
{
FVector PredictedLocation = Stimulus.StimulusLocation;
DrawDebugSphere(GetWorld(), PredictedLocation, 30.f, 18.f, FColor::Red, false, 7.f, 0.f, 0.3f);
BlackboardComp->SetValueAsVector(FName("PredictedLocation"), PredictedLocation);
}
}
else
{
UE_LOG(LogTemp, Warning,TEXT("Prediction sense didn't work"))
}
}
And here is the second code:
if (Stimulus.Type == SensePredictionID)
{
if (Stimulus.WasSuccessfullySensed())
{
FVector PredictedLocation = Stimulus.StimulusLocation;
//DrawDebugSphere(GetWorld(), PredictedLocation, 30.f, 18.f, FColor::Red, false, 7.f, 0.f, 0.3f);
FNavLocation NavLocation;
bool OnNavigationMesh = UNavigationSystemV1::GetCurrent(GetWorld())->ProjectPointToNavigation(PredictedLocation, NavLocation);
if (OnNavigationMesh)
{
FVector Z(0.f, 0.f, 120.f);
FVector RealPredictedLocation = NavLocation.Location + Z;
DrawDebugSphere(GetWorld(), RealPredictedLocation, 30.f, 18.f, FColor::Red, false, 7.f, 0.f, 0.3f);
BlackboardComp->SetValueAsVector(FName("PredictedLocation"), RealPredictedLocation);
}
}
else
{
UE_LOG(LogTemp, Warning,TEXT("Prediction sense didn't work"))
}
}