Vector3.Angle analog in C++

Hi all! Whats analog of Unity’s C# Vector3.Angle analog?

Vector3.Angle(unit.forward, DestPoint - unit.position)

I need find this angle in degrees.

I don’t believe Unreal has a function to compute the angle between two vectors, but it’s actually a fairly simple process. Mathematically, the dot product of two vectors is equal to the length of the two vectors multiplied by the cosine of the angle between them (see Dot product - Wikipedia ).

By dividing the dot product of the vectors by their length, and taking the arc cosine of this value, you can get the angle between them.

In code this would be something like

float AngleBetweenVectors(const FVector& A, const FVector& B)
{
	float AngleCosine = FVector::DotProduct(A, B) / (A.Size() * B.Size());
	float AngleRadians = FMath::Acos(AngleCosine);
	return FMath::RadiansToDegrees(AngleRadians);
}

Thanks! :slight_smile: