How to get an angle between 2 Vectors?

Updated the C++ code to be a bit more readable

// Assume you have two vectors, Vector1 and Vector2
FVector Vector1 = FVector(1, 0, 0);
FVector Vector2 = FVector(0, 1, 0);

// Normalize the vectors
Vector1.Normalize();
Vector2.Normalize();

// Calculate the dot product of the two vectors
float DotProduct = FVector::DotProduct(Vector1, Vector2);

// Calculate the angle in radians between the two vectors
float AngleInRadians = FMath::Acos(DotProduct);

// Convert the angle to degrees
float AngleInDegrees = FMath::RadiansToDegrees(AngleInRadians);

// Calculate the cross product of the two vectors
FVector CrossProduct = FVector::CrossProduct(Vector1, Vector2);

// If the Z component of the cross product is less than zero, the second vector is to the left of the first
if (CrossProduct.Z < 0)
{
    AngleInDegrees = -AngleInDegrees;
}
1 Like