Hello, i have a cube and i would like to know the angle between my forward vector and the cube’s face forward vector that i’m currently looking at. I have the following working logic:
FVector Normal = Cube->GetTransform().InverseTransformVectorNoScale(HitResult.Normal);
FVector Vector;
FString Side;
if (Normal.Equals(FVector(1.0f, 0.0f, 0.0f)))
{
Side = "Front";
Vector = Cube->GetActorForwardVector();
}
else if (Normal.Equals(FVector(0.0f, 1.0f, 0.0f)))
{
Side = "Right";
Vector = Cube->GetActorRightVector();
}
else if (Normal.Equals(FVector(-1.0f, 0.0f, 0.0f)))
{
Side = "Back";
Vector = -Cube->GetActorForwardVector();
}
else if (Normal.Equals(FVector(0.0f, -1.0f, 0.0f)))
{
Side = "Left";
Vector = -Cube->GetActorRightVector();
}
FVector Value = GetTransform().InverseTransformVectorNoScale(Vector);
float Angle = FMath::RadiansToDegrees(FMath::Atan2(Value.X, Value.Y));
This gives-me -90º when i’m looking directly to the face and it works, but i’m sure there has to be a better way to do this ! Thank you.