Having a problem with rotations (again)

Will check it out I’ve enver actually used the playercameramanager in my 2 years of unreal.

This is my code ATM. It doesnt return 0-360 but rather 0-180 postiive. And bearingTrue returns 180 when im pointed north (+x aka FVector::forwardVector aka 0,0,0 rotation) when it should return 0.

I actually never realized my own course went negative when I calculated (Get world rotation) it and turned -x or east (270 should be, but I get -90). could I just add 720 and mod 360 or just add 360?



void UBPFuncLib_TDChelper::Bearing(const APawn* TgtShip, const APawn* PlyrSub, float &brgTrue, float &brgRel)
{
	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?
}


Thank you for th help so far. Going to get 0-360 if it kills me!

brgRel works correctly when me and the ship are parrallel (90) but the whole north being 180 instead of 0 breaks the rest.

Edit: For what its worth, get controller rotation works… I’ll have to try to work with that somehow.
Edit: worldRotation + 720 % 360 doesnt work to create 0->90->180->270->359.99999999
Edit: Get controller rotation does indeed work

So the big issue is Get Control Rotation works fine for this, but I wont always have a perfectly lined up camera active to get my ships heading… How might I solve that, there simply MUST BE a way to get the 0-360 rotation of a mesh/scene component etc

Edit: So using GetWorldRotation I almost had it via this…

If wRot > 0 {return wRot}
else return wRot - 180 * 2 + 180 % 360.

This gave me 0-180 clockwise and from 0-270 counter clockwise at which point it went to 180 going down again.

This is really bugging me, I never even realized all my angles that rely on 360d are wrong, now I only have 1 correct angle (angleOnBow code above) of 5 needed instead of 3 of 5.

How can I get a scene components world rotation in 0-360 cw/ccw?

wopuld it be possible to do vector math?

0-90 90-180 180-270 and 270-360 based on +/- fwd and right vectors

+Forward compared to 1,0,0 = 0,0,0 (0) to 1,0,0 (90) and
-Right = 90 to 180

  • forward = 180 to 270
    +right = 270 to 360