Linetracing hardcoding pitch difference for LineTraceEnd

Hi all, I tried to do the line tracing for crosshair before watching the right solution.
I am aware that my solution is not good at all i just wanted to make it work before I learn how to do it properly.

For Line Trace start i used: player viewpoint location
For Line Trace end i used: player viewpoint location + player viewpoint rotation * reach and added hardcoded amount of pitch for the rotation.

I tried to calculate the amount of pitch that needs to be added using camera’s fieldofview, crosschair relative position on the screen and distance to the spring arm, However i ended up just picking the right angle manually.
The solution is working as expected(, I just wonder if anyone has any ideas why my calculated angle is different from what i actually have to add…

Height of visible world at spring arm plane (in world centimeters) is 2 * distance to a spring arm - 2000. (Half of the field view angle is 45 degr. which means that angle at the bottom of the screen is also 45 degr. This makes the bottom triangle еquilateral with a side of 1000)

Distance to a crosshair from the top of the screen is 33.3 % which is 2000*0.33=666. That leaves 1000-666 = 333 between crosshair and the spring arm.

angle = atan(333/1000)

My code:
GetSightRayHitLocation

Privacy & Terms