Inspired by the brilliant work of m8f on his Precise Crosshair mod I decided to write a simple function that dynamically adjusts weapons' projectile firing functions' pitch and angle to make it so that projectiles and hitscans always hit the crosshair.
From my testing everything seem to work as intended so I am releasing an example pk3 for modders
DOWNLOAD EXAMPLE PK3 (to be used with QC:DE)
All the firing functions examples are in ZScript.QCD
Code: Select all
Changelog 1.3: - better procedure; - added an example pk3 to be used with QC:DE. Changelog 1.2: - simplified angle/pitch calculation code (VectorAngle duh!); - fixed an issue where depending on the pitch at which you fired a non hitscan projectile it would warp to a different location after impacting with a solid surface. (I would very much love to record a video of what I mean but I am not going to be on my main computer for a few days) Changelog 1.1: It has been kindly brought to my attention that it is better to make the function calculating Angle and Pitch an Action, so the code has been slightly tweaked to make it work that way. I think it looks nicer and more compact
Spoiler:The way it works is quite simple, a line tracer (a non damaging hit scan attack of sort) is fired at your viewheight and is used to return the distance it traveled.
This distance represents the projection of the crosshair onto the map geometry.
Then basic trigonometry is used to determine which are the angle and pitch necessary to make the fired projectile travel toward the point of impact from the XY and Z offset you make it spawn at.
Here is a basic demonstration of it applied to a few of QC:DE's weapons I edited to use it.