Quick one: ever notice that weapon view bob, that is the weapon moving in time with the player as they walk, doesn’t work on certain weapons?

Me either, but weapons that derive from CHL2MPMachineGun don’t exhibit this behaviour.

It turns out that this is because CHL2MPMachineGun inherits directly from CWeaponHL2MPBase, instead of CBaseHL2MPCombatWeapon like all the other weapons.

The fix is simple, in weapon_hlwmpbase_machinegun.h just replace

1
#include "weapon_hl2mpbase.h"

with

1
#include "weapon_hl2mpbasehlmpcombatweapon.h"

and then replace

1
class CHL2MPMachineGun : public CWeaponHL2MPBase

with

1
class CHL2MPMachineGun : public CBaseHL2MPCombatWeapon

And that will give you your view bob back.CBaseHL2MPCombatWeapon also inherits CWeaponHL2MPBase so adding CBahseHL2MPCombatWeapon into the inheritance hierarchy gives you back the functionality that deals with setting up the view bob.

2 Responses to “Snippet: Fixing Weapon View Bob”

  1. BBG London Says:

    That was wonderful information. You did a good job communicating your message. Keep up the great job.

  2. Annetta Pentz Says:

    That’s a genuinely delicious cause theme , I really should have ascertained that couple of ages past. who cares, that’s what you are here for yes?

Leave a Reply