Third Person Shooter - Aiming at Crosshair

I started going in this direction. I did a line trace from the weapon and took the hit result, converted it to screen coordinates relative to the player’s viewport and drew a crosshair on the HUD at that location instead of the exact center where I had it. But this still wasn’t the MOST accurate.

The problem is if your camera is facing something you should hit, it’s possible that your gun, facing in that direction, would shoot behind the target.

To resolve this, I took the hit result from the gun’s line trace and performed a second line trace from the camera location to the gun’s hit result. If it found something between the camera and the gun’s hit result, use the new hit result instead.

The result is not bad. The crosshair does “float” around a bit as it now moves around the screen. It functions more like a laser sight now instead of a crosshair. But I think it will work.