Projectile based Weapons: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
This article explains some of the possibilities for projectile weapons like the crossbow or RPG, instead of the standard guns that hit or miss instantly. All tweaks in this article are based on the crossbow code. The relevant code can all be found in the server side part of the crossbow code. This is found under hl -> source files -> HL2 DLL -> weapon_crossbow.cpp | This article explains some of the possibilities for projectile weapons like the crossbow or RPG, instead of the standard guns that hit or miss instantly. All tweaks in this article are based on the crossbow code. The relevant code can all be found in the server side part of the crossbow code. This is found under ''hl -> source files -> HL2 DLL -> weapon_crossbow.cpp'' in the solution explorer | ||
== Adding spread == | == Adding spread == | ||
Spread can be added rather quickly. The GetAutoAimVector used in other weapons appears to do no good here, so another approach is needed. I basically use the aiming vector converted to angles to change these angles, and then convert it back to the aiming vector. The relevant code is found in the CWeaponCrossbow::FireBolt method, the lines that need to be changed are: | Spread can be added rather quickly. The ''GetAutoAimVector'' used in other weapons appears to do no good here, so another approach is needed. I basically use the aiming vector converted to angles to change these angles, and then convert it back to the aiming vector. The relevant code is found in the ''CWeaponCrossbow::FireBolt'' method, the lines that need to be changed are: | ||
'''594 - 595''' | '''594 - 595''' | ||
Line 25: | Line 25: | ||
== Obeying gravity == | == Obeying gravity == | ||
Crossbow bolts do not obey the sv_gravity server variable, which can be changed with the console, or I believe even on a per map basis by the mapper. In order to make this work properly, find the CCrossbowBolt::Spawn method and edit line no '''163''' (unmodified file): | Crossbow bolts do not obey the ''sv_gravity'' server variable, which can be changed with the console, or I believe even on a per map basis by the mapper. In order to make this work properly, find the ''CCrossbowBolt::Spawn'' method and edit line no '''163''' (unmodified file): | ||
<pre> | <pre> | ||
Line 45: | Line 45: | ||
</pre> | </pre> | ||
to the includes in the top of the file, otherwise the sv_gravity variable is not accessible. | to the includes in the top of the file, otherwise the ''sv_gravity'' variable is not accessible. |
Revision as of 02:28, 16 June 2006
This article explains some of the possibilities for projectile weapons like the crossbow or RPG, instead of the standard guns that hit or miss instantly. All tweaks in this article are based on the crossbow code. The relevant code can all be found in the server side part of the crossbow code. This is found under hl -> source files -> HL2 DLL -> weapon_crossbow.cpp in the solution explorer
Adding spread
Spread can be added rather quickly. The GetAutoAimVector used in other weapons appears to do no good here, so another approach is needed. I basically use the aiming vector converted to angles to change these angles, and then convert it back to the aiming vector. The relevant code is found in the CWeaponCrossbow::FireBolt method, the lines that need to be changed are:
594 - 595
QAngle angAiming; VectorAngles( vecAiming, angAiming );
these can be exchanged with:
QAngle angAiming; VectorAngles( vecAiming, angAiming ); angAiming.x += ((rand() % 250) / 100.0) * (rand() % 2 == 1 ? -1 : 1); angAiming.y += ((rand() % 250) / 100.0) * (rand() % 2 == 1 ? -1 : 1); AngleVectors(angAiming, &vecAiming);
This changes the x and y angles with up to 2.5 degrees in either direction. This actually results in a square spread instead of a cone, but at least it works. If anybody knows of a better approach, I would be happy to hear about it.
Obeying gravity
Crossbow bolts do not obey the sv_gravity server variable, which can be changed with the console, or I believe even on a per map basis by the mapper. In order to make this work properly, find the CCrossbowBolt::Spawn method and edit line no 163 (unmodified file):
SetGravity( 0.05f );
change it to:
SetGravity( sv_gravity.GetFloat() / 600);
Since the original value was 0.05, and gravity usually is set to 600 or 800, this means that the new gravity value will be larger, and the bolt will fly in a more pronounced arc. You will have to tweak the value as you see fit, but the bolt should now obey any server side changes in gravity.
In order to make this compile you will need to add
#include "movevars_shared.h"
to the includes in the top of the file, otherwise the sv_gravity variable is not accessible.