# Rotating arrow on screen towards actor

Hi Guys,

I would like to create a 2D UI widget which is an arrow pointing towards an actor. This widget rotates around the center of my screen like a clock hand (0 degrees is pointing at noon) and points to the target actor. I am making a flying game and this would be like the radar tracker. Its also very similar to the circular damage source indicators you see in fps games.

I am pretty bad with vector math, but given my actor location, my target actor location and my forward vector (and any other information I need), how can I derive the angle I need to rotate the widget to?

Thanks,

Hey, have you tried this?

Hey thanks for the reply Moshy,

I made a solution that seems to work. It feels a bit off, and its probably not the most efficient way to go about this, but visually, I can’t see anything too wrong about the behavior so I’ll post the code for what I did:

*** Start Code ***
FRotator MuzzleRotation = Camera->GetComponentRotation();
FVector MuzzleVector = MuzzleRotation.Vector();
MuzzleVector.Normalize();

FVector TargetVector = (TargetActor->GetActorLocation() - this->GetActorLocation());
TargetVector.Normalize();

RotationToTarget = TargetVector.Rotation() // ← This is what LookAtRotation() returns.

float TargetArrowAngleYaw = RotationToTarget.Yaw - MuzzleRotation.Yaw; //Get relative yaw to target
float TargetArrowAnglePitch = RotationToTarget.Pitch - MuzzleRotation.Pitch; //Get relative pitch to target

float dX = sin(FMath::DegreesToRadians(TargetArrowAngleYaw));
float dY = sin(FMath::DegreesToRadians(TargetArrowAnglePitch));

TargetArrowAngle = FMath::RadiansToDegrees(atan(dX / dY));
if (dY < 0 )
TargetArrowAngle += 180; //Make sure we are in the right quadrants

return TargetArrowAngle;
*** End Code ***

If somebody figures out a better way to do this please post it. Thanks guys.

Edit* Please ignore those smiley faces lol, I’m typing this reply from my laptop, don’t know how to get rid of them.