Heres the kicker.
This code doesnt work it stays 0-180-0 (or worse)
void UBPFuncLib_TDChelper::Bearing(const APawn* TgtShip, const APawn* PlyrSub, const UCameraComponent* ScopeCam, float &brgTrue, float &brgRel)
{
if (TgtShip == nullptr || PlyrSub == nullptr || ScopeCam == nullptr)
{
debug("TgtShip or PlyrSub or ScopeCam == nullptr in BPFuncLib_TDCHelper::Bearing");
}
else
{
FVector LoS = (PlyrSub->GetActorLocation() - TgtShip->GetActorLocation()); //Line of sight from playersub center to target ship center
LoS.Normalize();
brgRel = FMath::RadiansToDegrees(FGenericPlatformMath::Acos(FVector::DotProduct(PlyrSub->GetActorForwardVector(), LoS))); //Bearing relative temp
brgTrue = FMath::RadiansToDegrees(FGenericPlatformMath::Acos(FVector::DotProduct(FVector::ForwardVector, LoS))); //Bearing true from ForwardVector, is that north south?
if (brgRel < 0)
{
brgRel = brgRel + 360.f
}
if (brgTrue < 0)
{
brgTrue = brgTrue + 360;
}
}
}
Note I also tried using the UCameraComponent.GetForwardVector/location/upvector.
But the blueprint equivalent does work the following is PERFECT. (top is perfect, bottom using the code node gives wrong result as above)
So I guess I must ask for a gimme to continue learning, how do I repdouce the tpo half of the blueprint picture in code?