VERC: View Roll When Strafing (like DMC) Last edited 3 weeks ago2018-09-05 00:27:49 UTC by Penguinboy Penguinboy

This tutorial will show you how to achieve the view rolling effect while strafing, as in DMC and AHL. In fact, this code is the same code used in the DMC modification, I'm just showing you how to make it work for HLDM. Its quite easy actually, so lets get started...

Open hud.cpp first... go to around line 84, where you'll see this code:
extern client_sprite_t *GetSpriteList(client_sprite_t *pList, const char *psz, int iRes, int iCount);

extern cvar_t *sensitivity;
cvar_t *cl_lw = NULL;
After that set of code, add this:
// Mazor - used for view rolling when strafing
cvar_t *cl_rollangle;
cvar_t *cl_rollspeed;
Now, go in the function CHud::Init() and find these lines:
m_SayText.Init();
m_Menu.Init();

ServersInit();
MsgFunc_ResetHUD(0, 0, NULL );
Those should be right at the end of that function, before the final }. After that code, add this to initialize the cvar variables we defined above:
// Mazor - used for view rolling when strafing
cl_rollangle = gEngfuncs.pfnRegisterVariable ( "cl_rollangle", "0.65", FCVAR_CLIENTDLL|FCVAR_ARCHIVE );
cl_rollspeed = gEngfuncs.pfnRegisterVariable ( "cl_rollspeed", "300", FCVAR_CLIENTDLL|FCVAR_ARCHIVE );
Now thats it for hud.cpp, now open view.cpp.

Find the V_CalcViewRoll() function in that file around line 389, right above these lines:
void V_CalcViewRoll ( struct ref_params_s *pparams )
{
    cl_entity_t *viewentity;
Add this code to define the cvar's as external variables so the linker can make use of them at compile time:
// Mazor - used for view rolling when strafing
extern cvar_t *cl_rollangle;
extern cvar_t *cl_rollspeed;
Now that you defined the variables and initialized them with some sort of value, you can begin to use them, so go inside the function V_CalcViewRoll() to find the line:
viewentity = gEngfuncs.GetEntityByIndex( pparams->viewentity );
if ( !viewentity )
    return;
After that little bit of code, add this line to make everything complete:
//Roll the angles when strafing Quake style!
pparams->viewangles[ROLL] = V_CalcRoll (pparams->viewangles, pparams->simvel, cl_rollangle->value, cl_rollspeed->value ) * 4;
That should complete it. This will give you the view rolling when the player strafes from side to side. If desired, the user can customize how much and how fast they want to roll by changing the cvars: cl_rollangle and cl_rollspeed. The defaults are as follows: cl_rollangle = 0.65 and cl_rollspeed = 300. If you would like to change these to fit your needs, go right ahead. If not, enjoy!
This article was originally published on the Valve Editing Resource Collective (VERC).
TWHL only archives articles from defunct websites. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.