Hi all! I’m making an FPS in UE5 where the player can lock on to targets, similar to Metroid Prime. The lock-on is achieved by setting the player controller’s Control Rotation to the Look At Rotation between the camera’s location and the target actor’s location. I am lerping the rotation, but the problem I’m about to describe persists even when I skip the lerp and set the Control Rotation directly.
Here’s the problem: when I strafe around my target, instead of moving in a circle as expected, the player character gradually moves backward away from the target, forming a spiral pattern. This happens even faster if you set a higher movement speed.
I’ve found a few relevant threads on Reddit and here on the UE Forums, but the replies suggest adding an offset to the actor location while strafing to compensate for the drift. As far as I can tell, they recommend a brute-force approach to finding the correct offset for your movement speed.
However, if your character can both walk and sprint, you would need to find two offsets and apply them depending on whether the player is walking or sprinting. It gets even more complicated if your character can do a short-range dodge/dash maneuver.
My first question is: why does this happen at all? I would expect, if my control rotation is locked to my target, strafing would move me in a perfect circle around the target.
My second question is: what other solutions exist? Can I clamp my player’s movement to a circle around the target so long as there’s no input on the Y axis? Can I programmatically derive the exact offset required to maintain the same distance from the target (again, so long as there’s no input on the Y axis)?
I’m relatively new to Unreal and brand-new to the forums, so please let me know if I’ve neglected to include any information. I’ve attached a screenshot of my Lock Camera function below—it’s called on the built-in Look input axis events so long as the player is locked on to a target. The code is from this tutorial. Thanks!