GameBanana shows no ads to members. Sign up now!
Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

Viewmodel Tilting when Strafing

A Tutorial for Half-Life

So lets start by opening your client workspace and opening view.cpp.

1. Registering New Console Variables

On the top you will find some cvar definitions. After cvar_t *cl_chasedist; we will add these three new cvars.

cvar_t *cl_rollangles;
cvar_t *cl_rollspeed;
cvar_t *cl_tiltextra;

Now in the bottom find void V_Init (void) and before the end of the function add

cl_rollangles = gEngfuncs.pfnRegisterVariable( "cl_rollangles","0.65", 0 );

cl_rollspeed = gEngfuncs.pfnRegisterVariable( "cl_rollspeed","300", 0 );
cl_tiltextra = gEngfuncs.pfnRegisterVariable( "cl_tilt_extra","1.3", 0 );

So i will explain what these cvars do

cl_rollangles is the intensity of the gun tilt.
cl_rollspeed is the speed of the tilt.
cl_tilt_extra will be multiplied with the tilt.

2. Implementing The Weapon Tilt

Now find the V_CalcViewRoll function.

void V_CalcViewRoll ( struct ref_params_s *pparams )

and then change it to this

void V_CalcViewRoll ( struct ref_params_s *pparams, vec3_t &angles )

Now inside the function you will find these lines

side = V_CalcRoll ( viewentity->angles, pparams->simvel, pparams->movevars->rollangle, pparams->movevars->rollspeed );

pparams->viewangles[ROLL] += side;

and change it to look like this

side = V_CalcRoll ( viewentity->angles, pparams->simvel, cl_rollangles->value, cl_rollspeed->value )*4;

// pparams->viewangles[ROLL] += side; // delete the comment if you want viewroll

and also add this line below the new code

angles[ROLL] = angles[ROLL] + side * cl_tiltextra->value;

Now inside the CalcNormalRefDef function and inside the function find

V_CalcViewRoll ( pparams );

and change it to this

V_CalcViewRoll ( pparams, view->curstate.angles );

Now it should like like this

Play around with the values to suit your taste.

I also recommend using this with Admer456's Advanced View Bobbing tutorial since it looks like a more modern view bobbing.

If you have any problems please tell me in the comments.
Sign up to access this!


Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code


Key Authors


bluenighthawk4906 avatar
bluenighthawk4906 Joined 6y ago
186 points Ranked 58643rd
Sign up to access this!
Sign up to access this!
Sign up to access this!


Sign up to access this!



Difficulty Level



  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • Today's Pick
    Featured on Jun 6 2020
  • 8
  • 3.3k
  • 6
  • 29d
  • 25d

More Programming Tutorials