Home   Help Search Login Register  

Author Topic: initSpeed in cfgWeapons  (Read 3174 times)

0 Members and 1 Guest are viewing this topic.

Offline Fincuan

  • Members
  • *
initSpeed in cfgWeapons
« on: 16 Sep 2009, 23:27:40 »
While just browsing the configs I saw that a few weapons have initSpeed defined in cfgWeapons, which got me thinking: We all know how in A2 the initial speed of the bullet is decided by the type of the magazine, and hence an M4 has exactly the same muzzlevelocity as an M16. Why couldn't we change this then? Why don't we define our own parameter for muzzlevelocity in the weapon's config, for example hijacking initSpeed?

When this is done would just add a "fired" eventhandler that reads the new initialspeed and sets it to each bullet fired. The performance impact of such measures is a mystery to me, but in my opinion you could only limit this kind of behaviour to bullets fired by the player. What the AI does is not that important.

edit: New downloadlink below

I didn't find any previous discussion on this and haven't seen any addons use this, so forgive me if it's all old news or just a bad idea  :D

edit:

Continuing the monologue here, I rewrote the example addon to a slightly different approach and added some weapons. The link above is still valid. It should now "fix" muzzle velocities for all M4/M16s, G36s, XM8s and AKs. Currently only the player's weapon is handled, but extending it to AI would be the matter of removing one "if"-check.
« Last Edit: 18 Sep 2009, 15:49:20 by Fincuan »

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: initSpeed in cfgWeapons
« Reply #1 on: 18 Sep 2009, 12:59:00 »
Interesting! :good:

Here are some random thoughts/notes:
  • Keep in mind that changing the bullet speed also changes the bullet penetration. Simply sticking to raw numbers while not looking at the actual performance might unbalance the game.
  • What about subsonic ammunition? Both gun and ammo are factors when it comes to muzzle velocity. Ignoring one can't be right.
  • The use of exitWith outside do, for, count or forEach "is not guaranteed to work reliably".

try { return true; } finally { return false; }

Offline Fincuan

  • Members
  • *
Re: initSpeed in cfgWeapons
« Reply #2 on: 18 Sep 2009, 13:13:08 »
Thanks for the reply. I'll look into that exitwith problem, but so far I haven't seen it fail even once. I guess there's a first time for everything, and at least the fix is easy. Penetration is something I have to test more, but if the A2 engine takes speed into account properly it shouldn't be a problem. Less speed -> worse penetration. Different types of ammunition was indeed a big shortcoming, and that's why... see blow :)

edit:
Right, new approach again

The above approach wasn't really that flexible in terms of different ammunition fired with the same weapon, so a new one was needed. Insted of specifying initial speed in the config I decided on a base-weapon for each calibre, with a velocityfactor of 1, and then factored other weapons of the same calibre in relation to this vs. their expected muzzlevelocity with standard ammunition. Ie. M16, the "base weapon" for 5.56x45, has a velocityfactor of 1, while a shorter-barreled M4 has a factor of 0.946. By default the 5.56x45 Stanags give these weapons a muzzlevelocity of 930 m/s, but now that of M4 would be 0.946*930 m/s = 879.78 m/s. All mags containing the same type of ammo also now give the same inital speed, ie. a G36 Mag doesn't have different speed compared to Stanags anymore.

Imho this is way more flexible than the above in terms of different ammunition, as ANY type of ammo could now be fired and barrel length would still affect the initial speed.

Attached is a sample addon and an examplemission. In the mission I've added a "fired" Eventhandler to the playerunit so that you get written feedback of the weapon, muzzle and muzzlevelocity every time you fire. This version of the addon also has the effect enabled on all infantrymen that are local to the player, just to see how it affects performance in large scale.

Download example mission and addon(Requires CBA)
Do not mirror
« Last Edit: 18 Sep 2009, 16:20:11 by Fincuan »