How to Get Angle between 2 Vectors ? with relative to actors current forward

How do i get Angle between 2 Vectors with relative to actors forward Direction ?

Use the find look at rotation node, use the start and target location (vector) and add the result to the character rotation.
Almost sure that`s the correct way :slight_smile:

Hope this helps!

You can calculate the angle between two direction vectors like followed:
FMath::Acos(FVector::DotProduct(DirectionVec1, DirectionVec2));

The Direction Vectors have to be normalized before doing that calculation.

What do you mean by "Relative to Actors forward Direction?

"What do you mean by “Relative to Actors forward Direction?”

Getting the angle between actor and hit location, With relative to actors’s current rotation.

at the moment using the look at rotation, getting yaw value from the rotaror and subtracting with the actor’s yaw value. I’m getting the desired result but need a effective way to do it.

ah ok

You get the direction vector of the hit location and the actor by:

FVector DirectionVec = Hit.Location - Actor->GetActorLocation();
DirectionVec.Normalize();

FVector ActorForward = Actor-> GetActorForwardVector();
ActorForward.Normalize(); //Should already be normalized, but just in case…

float AngleInDegree = FMath::Acos(FVector::DotProduct(DirectionVec, ActorForward ));

I think this is the best way to do it.
Maybe unreal has some built-in function to calculate it?

Greetings

hey, this method wasn’t working for me some for some reasons. Sorry for late reply

FMath::Acos() returns angle in radians. so you may need to add another line:

AngleInDegree = FMath::RadiansToDegrees(AngleInDegree);

now the variable AngleInDegree is really in degrees ^^