Getting increased distance when rotating around target actor

Hello all,

So I’ve been using a really simple targeting system for a prototype I’m working on. Basically I have the camera locked onto the target actor while using the TPP MoveForward and MoveRight functions to move around the target. The issue I keep running into is that while running around the target, my distance from the target keeps growing. This continues to happen even when I normalize the vector(s).



const FRotator Rotation = (GetNearestEnemy()->GetActorLocation() - GetActorLocation()).Rotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FRotator ControlRot(Controller->GetControlRotation().Pitch, Rotation.Yaw, 0);
Controller->SetControlRotation(ControlRot);

// Get the forward vector of the target
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(Direction, Value);

Again, even when I normalized every vector listed above, it still increases the distance.

Also, I tried using FQuat::Slerp instead, but not sure I was using it correctly. Below I’ll drop in what I was trying with slerp:



const FQuat AQuat(GetNearestEnemy()->GetActorRotation());
const FQuat BQuat(GetActorRotation());
const FRotator Rotation = FQuat::Slerp(AQuat, BQuat, 0.1f).Rotator();
const FRotator YawRotation(0, Rotation.Yaw, 0);
const FRotator ControlRot(Controller->GetControlRotation().Pitch, Rotation.Yaw, 0);
Controller->SetControlRotation(ControlRot);

// Get the forward vector of the target
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
AddMovementInput(Direction, Value);

When I use the slerp function as above, the player just runs left/right in a straight line, not around the target. When I swap the A and B parameters, the player just rotates around in a circle where he’s standing.

I’m sure I’m just missing something obvious, but could use some help. Thanks :)!!!