I saw a page on the VDC that had code for camera bobbing and so I added it to my mod, and I really shouldn't expect much from eight year old code, but it didn't work. It didn't cause compile errors, though. I'm no programmer other than in Unity, so I don't know what could be causing the problem. Help would be extremely appreciated!
EDIT: This is the page I'm referring to: [url]https://developer.valvesoftware.com/wiki/Camera_Bob[/url]
If you put some debug output in the if statement does it get printed?
Try changing the x and y offset values manually and see if the function call "ViewPunch" is even doing anything.
Oh yeah, also debug it and see if it ever reaches that function.
[QUOTE=Karmah;52638179]Try changing the x and y offset values manually and see if the function call "ViewPunch" is even doing anything.
Oh yeah, also debug it and see if it ever reaches that function.[/QUOTE]
[QUOTE=twit;52638152]I'm no programmer other than in Unity[/QUOTE]
Don't know how to debug a function
Then maybe you're in too far over your head?
[QUOTE=Karmah;52638257]Then maybe you're in too far over your head?[/QUOTE]
I asked for help, not to get told off for not knowing (probably) basic programming!
Here's the code you linked in your post
[code]
if ( cl_viewbob_enabled.GetInt() == 1 && !engine->IsPaused() )
{
float xoffset = sin( gpGlobals->curtime * cl_viewbob_timer.GetFloat() ) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 100;
float yoffset = sin( 2 * gpGlobals->curtime * cl_viewbob_timer.GetFloat() ) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 400;
player->ViewPunch( QAngle( xoffset, yoffset, 0));
}[/code]
The first line is an IF statement: the lines that follow it between the [B]{[/B] and [B]}[/B] brackets will execute only if cl_viewbob_enabled is set to 1 and the engine isn't paused (notice the [B]![/B] infront if (engine->IsPaused()) meaning opposite)
on lines 3 and 4 you calculate x and y offset variables. This is the heart of the camera bobbing logic, as it calculates how much to rotate the camera on the x and y axis (I think).
on line 5 the player's ViewPunch function is called, taking in an QAngle with the 2 angles just calculated.
There are 3 obvious points of error here. Either the ViewPunch function doesn't work, the x and y offset angles aren't getting calculated right, or the whole if statement isn't being reached.
The first 2 can be test at once. Try replacing xoffset or yoffset with a fixed number, like 20 or something and see if the player camera is always bobbed down or in some direction.
If the camera is rotated in some direction, then the perhaps the variables being used to calculate the x and y offsets aren't working.
If that doesn't do anything, then maybe those lines aren't being reached because cl_viewbob_enabled doesn't equal 1 and or engine paused is always true.
To test that, you could use a debugger and set a breakpoint on any line within that IF statement, or set another function like something to kill the player or better yet write out to the console (something to tell you that the code IS executing)
[editline]1st September 2017[/editline]
Do you even have the preferences set in your config file to enable this? Like calling in the console cl_viewbob_enabled 1 and cl_viewbob_timer 10 and cl_viewbob_scale 0.05 ?
[QUOTE=Karmah;52638298]Here's the code you linked in your post
[code]
if ( cl_viewbob_enabled.GetInt() == 1 && !engine->IsPaused() )
{
float xoffset = sin( gpGlobals->curtime * cl_viewbob_timer.GetFloat() ) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 100;
float yoffset = sin( 2 * gpGlobals->curtime * cl_viewbob_timer.GetFloat() ) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 400;
player->ViewPunch( QAngle( xoffset, yoffset, 0));
}[/code]
The first line is an IF statement: the lines that follow it between the [B]{[/B] and [B]}[/B] brackets will execute only if cl_viewbob_enabled is set to 1 and the engine isn't paused (notice the [B]![/B] infront if (engine->IsPaused()) meaning opposite)
on lines 3 and 4 you calculate x and y offset variables. This is the heart of the camera bobbing logic, as it calculates how much to rotate the camera on the x and y axis (I think).
on line 5 the player's ViewPunch function is called, taking in an QAngle with the 2 angles just calculated.
There are 3 obvious points of error here. Either the ViewPunch function doesn't work, the x and y offset angles aren't getting calculated right, or the whole if statement isn't being reached.
The first 2 can be test at once. Try replacing xoffset or yoffset with a fixed number, like 20 or something and see if the player camera is always bobbed down or in some direction.
If the camera is rotated in some direction, then the perhaps the variables being used to calculate the x and y offsets aren't working.
If that doesn't do anything, then maybe those lines aren't being reached because cl_viewbob_enabled doesn't equal 1 and or engine paused is always true.
To test that, you could use a debugger and set a breakpoint on any line within that IF statement, or set another function like something to kill the player or better yet write out to the console (something to tell you that the code IS executing)
[editline]1st September 2017[/editline]
Do you even have the preferences set in your config file to enable this? Like calling in the console cl_viewbob_enabled 1 and cl_viewbob_timer 10 and cl_viewbob_scale 0.05 ?[/QUOTE]
[CODE]void CGameMovement::WalkMove( void )
{
if (cl_viewbob_enabled.GetInt() == 1 && !engine->IsPaused())
{
float xoffset = sin(gpGlobals->curtime * cl_viewbob_timer.GetFloat()) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 100;
float yoffset = sin(2 * gpGlobals->curtime * cl_viewbob_timer.GetFloat()) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 400;
player->ViewPunch(QAngle(xoffset, yoffset, 0));
Msg("function called");
}[/CODE]
I added the Msg() function and it wasn't printed. (hopefully that was the correct function)
Also: [QUOTE]Do you even have the preferences set in your config file to enable this? Like calling in the console cl_viewbob_enabled 1 and cl_viewbob_timer 10 and cl_viewbob_scale 0.05 ?[/QUOTE]
I set the CVars to default to those values so that's not the problem.
Try
[code]
if (cl_viewbob_enabled.GetInt() == 1)
Msg("First variable is fine");
if (!engine->IsPaused())
Msg("Second variable is fine");
[/code]
Add this before the first if statement. A roundabout way of checking which of the 2 conditions aren't being met because it sounds like one of them (or both) aren't.
If you see "First variable is fine" and not "Second variable is fine", then the check for "if the engine isn't paused" is always coming up "paused". If the reverse, then the viewbob isn't enabled. If neither then both of those problems are happening.
[QUOTE=Karmah;52638490]Try
[code]
if (cl_viewbob_enabled.GetInt() == 1)
Msg("First variable is fine");
if (!engine->IsPaused())
Msg("Second variable is fine");
[/code]
Add this before the first if statement. A roundabout way of checking which of the 2 conditions aren't being met because it sounds like one of them (or both) aren't.
If you see "First variable is fine" and not "Second variable is fine", then the check for "if the engine isn't paused" is always coming up "paused". If the reverse, then the viewbob isn't enabled. If neither then both of those problems are happening.[/QUOTE]
Tried it, still no workie.
The code I posted wasn't a solution
What messages appear, if any?
[QUOTE=Karmah;52638672]The code I posted wasn't a solution
What messages appear, if any?[/QUOTE]
I meant I got nothing, including console messages. I did word it confusingly.
Okay replace that with this then:
[code]
Msg("Are we even reaching WalkMove");
[/code]
So that your code should look something like this:
[code]
void CGameMovement::WalkMove( void )
{
Msg("Are we even reaching WalkMove");
if (cl_viewbob_enabled.GetInt() == 1 && !engine->IsPaused())
{
float xoffset = sin(gpGlobals->curtime * cl_viewbob_timer.GetFloat()) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 100;
float yoffset = sin(2 * gpGlobals->curtime * cl_viewbob_timer.GetFloat()) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 400;
player->ViewPunch(QAngle(xoffset, yoffset, 0));
Msg("function called");
}
}
[/code]
If you don't even see "Are we even..." in the console, then the whole WalkMove function isn't even getting called.
[QUOTE=Karmah;52638769]Okay replace that with this then:
[code]
Msg("Are we even reaching WalkMove");
[/code]
So that your code should look something like this:
[code]
void CGameMovement::WalkMove( void )
{
Msg("Are we even reaching WalkMove");
if (cl_viewbob_enabled.GetInt() == 1 && !engine->IsPaused())
{
float xoffset = sin(gpGlobals->curtime * cl_viewbob_timer.GetFloat()) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 100;
float yoffset = sin(2 * gpGlobals->curtime * cl_viewbob_timer.GetFloat()) * player->GetAbsVelocity().Length() * cl_viewbob_scale.GetFloat() / 400;
player->ViewPunch(QAngle(xoffset, yoffset, 0));
Msg("function called");
}
}
[/code]
If you don't even see "Are we even..." in the console, then the whole WalkMove function isn't even getting called.[/QUOTE]
Tested it, still no response. This is going way deeper than I thought it would.
All signs thus far seem to suggest that your game movement function isn't even getting called. Are you sure your code is actually compiling and not failing and running the old executable?
Are you sure the Msg() function works too? Because all of these is for naught if it doesn't actually print the text to the console
[QUOTE=Karmah;52638801]All signs thus far seem to suggest that your game movement function isn't even getting called. Are you sure your code is actually compiling and not failing and running the old executable?
Are you sure the Msg() function works too? Because all of these is for naught if it doesn't actually print the text to the console[/QUOTE]
[IMG]http://i.imgur.com/MKUvmDs.png[/IMG]
[IMG]https://imgur.com/wzowgEz[/IMG]
[editline]1st September 2017[/editline]
[IMG]http://i.imgur.com/wzowgEz.png[/IMG]
[editline]1st September 2017[/editline]
guess i gotta suck some penus now
im an idiot
I was only compiling the Client and not the Server. The viewbobbing was serverside. Sorry for wasting your time.
I didn't read much of the thread, but how is viewbobbing serverside?
[QUOTE=VIoxtar;52643107]I didn't read much of the thread, but how is viewbobbing serverside?[/QUOTE]
I dont think it is, last I recalled gamemovement.cpp is in the client, not the server.
:snip:
Sorry, you need to Log In to post a reply to this thread.