The line trace used the in lecture, even with a 100,000 Km range will return a hit location of (0.f,0.f,0.f) when aimng at the sky . This will cause UGameplayStatics::SuggestProjectileVelocity to always return true, and confuse the fk* out of you.
The source of the bug i believe is here
if (GetWorld()->LineTraceSingleByChannel(
HitResult,
StartLocation,
EndLocation,
ECollisionChannel::ECC_Visibility))
{
outHitLocation = HitResult.Location;
For some reason visibility doesn’t return the sky sphere, so the only way you can tell if SuggestProjectileVelocity is working correctly when expected to fail is by setting a very low projectile speed that cannot hit the range of the edge of your map.
To make things more confusing, behind the scenes in the lecture he must have changed his launch projectile speed to something very low (previously it was about 3,000 m/s), but you do not observe this until you watch to very end of the video where you see his output results reflecting that of low velocity. (except for the sky where in our version it doesnt work)
I suggest changing your code logs to reflect this:
bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
this,
outLaunchVelocity,
StartLocation,
AimLocation,
LaunchSpeed,
false,
0.f,
0,
ESuggestProjVelocityTraceOption::DoNotTrace,
FCollisionResponseParams::DefaultResponseParam,
ActorList,
true);
if (bHaveAimSolution && AimLocation != FVector(0.f)) {
FVector SuggestedDirection = outLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(SuggestedDirection);
auto time = GetWorld()->GetTimeSeconds();
UE_LOG(LogTemp, Warning, TEXT("%s %f Aim solution found for world location %s. Suggested Direction: %s . Suggested Veolocity: %s"), *GetOwner()->GetName(), time, *AimLocation.ToString(),*SuggestedDirection.ToString(), *outLaunchVelocity.ToString())
}
else if (AimLocation == FVector(0.f)) {
UE_LOG(LogTemp, Warning, TEXT("%s %f Did not input an end location greater then 0.f,0.f,0.f"), *GetOwner()->GetName(), GetWorld()->GetTimeSeconds())
}
else {
UE_LOG(LogTemp, Warning, TEXT("%s %f No valid suggested velocity found"), *GetOwner()->GetName(), GetWorld()->GetTimeSeconds())
}
This way you can tell if the aim location you send in is location (0,0,0), which is always true when you aim at the sky. This will prevent incorrect validation of something like, ‘bIsReachable’, in the future.
There is another strange difference from the current unreal code and the lecture’s If you notice I filled in all the variables for SuggestProjectileVelocity. In the video he says you do not need to set many of these; but if you try not setting ANY of them your program will return errors. If anyone knows why my compiler is telling me these default values must be filled in, please let me know, or if you get the same problem.