[API Noob] How to calculate a relative angle in CPP/UE4

So I did your example exactly and got these results with the following code

.H



public:

	//Functions
	UFUNCTION(BlueprintCallable, Category = "cpp")
	static float AngleOnBow(APawn* TargetShip, APawn* PlyrShip);


.CPP



float UBPFuncLib_TDChelper::AngleOnBow(APawn* TargetShip, APawn* PlyrShip)
{
	FVector LineSight = (PlyrShip->GetActorLocation() - TargetShip->GetActorLocation());
	float BowAngleInDeg = FMath::RadiansToDegrees(FGenericPlatformMath::Acos(FVector::DotProduct(TargetShip->GetActorForwardVector(), LineSight)));
	
	if (FVector::DotProduct(TargetShip->GetActorRightVector(), LineSight) < 0.0f) // We need one more dot product to actually figure out our winding
	{
		BowAngleInDeg *= -1;
	}
	return BowAngleInDeg;
}


But then I normalize it and it APPEARS to work. Will get back with more details.



float UBPFuncLib_TDChelper::AngleOnBow(APawn* TargetShip, APawn* PlyrShip)
{
	FVector LineSight = (PlyrShip->GetActorLocation() - TargetShip->GetActorLocation());
	LineSight.Normalize();
	float BowAngleInDeg = FMath::RadiansToDegrees(FGenericPlatformMath::Acos(FVector::DotProduct(TargetShip->GetActorForwardVector(), LineSight)));
	
	if (FVector::DotProduct(TargetShip->GetActorRightVector(), LineSight) < 0.0f) // We need one more dot product to actually figure out our winding
	{
		BowAngleInDeg *= -1;
	}
	return BowAngleInDeg;
}


What would be the best way to set it to 180d if its say 0.1 to - 0.1 (Your directly in the front of the ship, it should still return 180 not 0)

I think this is workable regardless! Thank you! :slight_smile: :smiley: :slight_smile: :smiley: