Projects that alter game functions but do not include new maps belong here.
Forum rules
The Projects forums are only for projects. If you are asking questions about a project, either find that project's thread, or start a thread in the General section instead.
I AM NO LONGER INVOLVED IN DOOM MODDING, YOU ARE FREE TO USE THIS A YOU PLEASE (JUST MENTION MY NAME SOMEWHERE IN THE CREDITS OUT OF CURTESY).
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
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
STEPS FOR MOD IMPLEMENTATION:
Spoiler:
1 - set your player.viewheight and player.attackZoffset so that a projectile fired without any XY and Z Offset will be fired exactly at the crosshair's height.
For example: with the regular DoomGuy player.viewheight of 41 you will need to set player.attackZoffset at 17;
2 - Add this Action to your weapon's code, if all your weapons are inheriting from a common one you only need to place it in the code of the "parent" weapon;
3 - edit your fire frame using this as a reference (you can use any projectile firing function, in this example I am using A_FireProjectile just because)
TNT1 A 0 //or whatever is the sprite you are using
{
double XYOffset = CHOOSE_YOUR_XYOFFSET;
double ZOffset = CHOOSE_YOUR_ZOFFSET;
Double AccurateAngle, AccuratePitch;
[AccurateAngle, AccuratePitch] = AnglePitchCalculator(XYOffset, ZOffset);
A_FireProjectile("YOUR_PROJECTILE",AccurateAngle,true,XYOffset,ZOffset,0,AccuratePitch);
}
4 - To make sure non hitscan projectile hit the desired location set up inheritance from FastProjectile, even if you projectile speed is not significant.
DO NOT DO THIS IF YOUR PROJECTILE IS A GRENAKE-LIKE PROJECTILE
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.
Last edited by Ivory Duke on Sun Nov 15, 2020 10:46 am, edited 5 times in total.