Just wanted to share a little function I’ve created, its a simple line trace. But the reason its useful is because when I implemented a camera zoom function that adjusted the spring arm length I noticed my interaction trace was getting longer or shorter depending on the camera position which meant at full zoom out my player couldn’t interact with things directly under them, and when fully zoomed in the player could interact with things much further away than intended.
This is probably not the best solution for a shooter trace, but for interacting it works quite well to keep the trace distance more consistent. Initially I was doing a trace with
pseudo code.
Start = GetCameraManager→GetCameraLocation()
End = Start + ( CameraManager(ForwardVector) * Distance) )
I tested a bunch of different solutions from tracing from different locations like the head, or actor location, using de-projected screen world direction, tracing from the head to the center of the screen etc etc. All of those had some kind of draw back. Like when tracing from the head there were cases when to close to a wall that the crosshair position wouldn’t correlate to the Hit point but away from a wall it worked well.
The key here was to use the head as a reference point to start the trace in the direction of the cameras forward vector. By using this as a start point it became almost perfectly consistent, the difference is very marginal when zooming in or out and probably wouldn’t be noticed by the player
Start= FindClosestPointOnLine(Point GetPlayerCharacter()→SocketLoc(head), LineOrigin GetPlayerCameraManager()→GetCameraLocation(), LineDirection GetPlayerCameraManager→GetActorForwardVector())
End = Start + ( GetPlayerCameraManager()→GetActorForwardVector() * TraceDistance )
In my personal code i do a CapsuleTrace() at this end/at the impact to make it easier to interact depending on if there is a hit, but that’s more optional.

