Convincing Head-bob in Source

Grab your favourite IDE and tinker with the innards of game engines

Convincing Head-bob in Source

Postby fishshapedfish on Mon Jun 11, 2012 6:15 pm

I've been trying to get a convincing head-bob working in our mod for a while now and I can't seem to get it to look right. At the moment it just looks as if the player was nodding their head. Any ideas + sample code I can use to create a convincing look? :smt023
Check Out the Team's Latest Mod!
WIP Screenshots
Recruiting/Our Goals
User avatar
fishshapedfish
Regular
Regular
 
Joined: Fri Aug 05, 2011 5:44 pm

Re: Convincing Head-bob in Source

Postby Armageddon on Mon Jun 11, 2012 9:36 pm

This doesn't exactly look convincing but it's good enough and can be tweaked.
https://developer.valvesoftware.com/wiki/Camera_Bob
User avatar
Armageddon
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Sun Dec 14, 2008 5:53 am

Re: Convincing Head-bob in Source

Postby Epifire on Tue Jun 12, 2012 1:26 am

Looking forward to see the results on this. Just as another note, what coding options are available for some horizontal sway to add in along with the vertical nodding mentioned?
Image
User avatar
Epifire
Senior Member
Senior Member
 
Joined: Fri Mar 25, 2011 8:54 pm
Location: Minnesota, where you're froze 24/7

Re: Convincing Head-bob in Source

Postby stoopdapoop on Tue Jun 12, 2012 3:01 am

everything is possible in code.

and arma, I'm sure that's the tutorial he used to get where he is now. It's not so tweakable.

I kinda wish that tutorial didn't exist, you see the same ULTRA shitty looking "headbob" in a bunch of mod videos and a couple of released mods.
I'm Brown
Image
User avatar
stoopdapoop
Veteran
Veteran
 
Joined: Sun Aug 21, 2005 2:14 am
Location: Ann Arbor, MI

Re: Convincing Head-bob in Source

Postby fishshapedfish on Tue Jun 12, 2012 6:36 pm

I had a go with that "headbob" code. It's even worse than mine. You can't really tweak it either as stoopdapoop said so I think I'll stick to my code which works on a similar system of viewpunches. I can easily make changes to my code so I'll try to add some horizonal view offset and rotation.
Check Out the Team's Latest Mod!
WIP Screenshots
Recruiting/Our Goals
User avatar
fishshapedfish
Regular
Regular
 
Joined: Fri Aug 05, 2011 5:44 pm

Re: Convincing Head-bob in Source

Postby Jordash on Wed Jun 13, 2012 12:33 am

In the code's defence, it is quite tweakable, you just have to be familiar with trigonometry.
User avatar
Jordash
Been Here A While
Been Here A While
 
Joined: Mon Sep 21, 2009 10:36 am
Location: Perth, Australia

Re: Convincing Head-bob in Source

Postby stoopdapoop on Wed Jun 13, 2012 1:22 am

you have to be familiar with trig for most game programming, but no amount of trig in the world will make

Code: Select all
player->ViewPunch( QAngle( xoffset, yoffset, 0));


into a convincing headbob.
I'm Brown
Image
User avatar
stoopdapoop
Veteran
Veteran
 
Joined: Sun Aug 21, 2005 2:14 am
Location: Ann Arbor, MI

Re: Convincing Head-bob in Source

Postby stoopdapoop on Wed Jun 13, 2012 2:37 am

Code: Select all
   if(IsSprinting())
   {
      Vector newoffset = GetViewOffset();
      Vector lean,jump;
      AngleVectors(EyeAngles(),NULL,&lean, &jump);
      newoffset.x = lean.x * sin(gpGlobals->curtime * 10.0f) * 10.0f;
      newoffset.y = lean.y * sin(gpGlobals->curtime * 10.0f) * 10.0f;
      newoffset.z = (jump.z * cos(gpGlobals->curtime * 20.0f) * 5.0f) + VEC_VIEW.z;
      SetViewOffset(newoffset);
   }
   else
   {
      SetViewOffset(VEC_VIEW);
   }


kinda hacky, but it's a base for a better bob. Those magic numbers should be replaced by convars or something and ideally you wouldn't setviewoffset every frame. The motion involves the obvious side to side motion and the "up-down" motion is lowest at the sides, and highest in the middle. It's like tracing an arch repeatedly. Looks at least alright, in my opinion.

This belongs somewhere in the hl2player class. It feels dirty puting viewbob code in GameMovement.cpp

What does your current method look like?
I'm Brown
Image
User avatar
stoopdapoop
Veteran
Veteran
 
Joined: Sun Aug 21, 2005 2:14 am
Location: Ann Arbor, MI

Re: Convincing Head-bob in Source

Postby Jordash on Wed Jun 13, 2012 3:54 am

Oh god, I didn't read the end of that wiki article, why would they set up a sine graph only to use a view punch! I assumed it would use SetView or something like that.

You should append the wiki article with your code, stoop, it looks pretty good.
User avatar
Jordash
Been Here A While
Been Here A While
 
Joined: Mon Sep 21, 2009 10:36 am
Location: Perth, Australia

Re: Convincing Head-bob in Source

Postby milkywaym16 on Mon Jun 18, 2012 8:57 am

A better way to do this would be to find out how to track which foot is stepping at that time and then do a specific viewpunch or whatever in a specific direction, and then do the same for the next foot. It doesn't necessarily have to track footsteps but it should track an alternating viewpunch or something so that it punches at opposite intervals of footsteps. The problem with the current system is that I don't think it's customizable enough. Each one looks pretty much the same because they have similar methods of implementation, even though stoopdapoop's is best code-wise.
milkywaym16
Just Joined
Just Joined
 
Joined: Thu Jun 30, 2011 8:43 am

Re: Convincing Head-bob in Source

Postby Epifire on Mon Jun 18, 2012 4:01 pm

That is totally what I said milk. Just finding out how to time the effect in with the foot steps. Technically if you were working with view elevation, you would want to drop it between steps, and then come back up with the footstep sounds. Just go walking around and you will see what I mean. XD
Image
User avatar
Epifire
Senior Member
Senior Member
 
Joined: Fri Mar 25, 2011 8:54 pm
Location: Minnesota, where you're froze 24/7

Re: Convincing Head-bob in Source

Postby fishshapedfish on Mon Jun 18, 2012 7:24 pm

Maybe it would be easier to have the crosshair moving rather than the whole view, I remember another mod doing this and it looking quite convincing . I'll see how it looks if I can code it.
On another note have you ever noticed how the gun bobs as you walk, maybe I should code the crosshair movement to match this?
Check Out the Team's Latest Mod!
WIP Screenshots
Recruiting/Our Goals
User avatar
fishshapedfish
Regular
Regular
 
Joined: Fri Aug 05, 2011 5:44 pm

Re: Convincing Head-bob in Source

Postby Gary on Mon Jun 18, 2012 7:25 pm

You could easily add animation events to track that. Animation events are basically a way to call functions through the qc/model at a specific frame.

Animation_Events
Have a question related to modding or something I posted? Something that needs staff attention? I haven't been active lately, but feel free to PM me or message me on Steam(link below)

User avatar
Gary
Interlopers Staff
Interlopers Staff
 
Joined: Wed Dec 16, 2009 12:40 am
Location: USA, FL

Re: Convincing Head-bob in Source

Postby fishshapedfish on Mon Jun 18, 2012 7:36 pm

Thanks, If I did that I could even have the crosshair moving with reloads, idle animations and I could even use it with the fire animations and remove the default view offset recoil. On the other hand I would have to recompile all of the hl2 weapons and more so I'll try a different method. I understand that this weapon bob is completely scripted so if I could find this code I could use its values in the crosshair movement.
Check Out the Team's Latest Mod!
WIP Screenshots
Recruiting/Our Goals
User avatar
fishshapedfish
Regular
Regular
 
Joined: Fri Aug 05, 2011 5:44 pm

Re: Convincing Head-bob in Source

Postby nub on Tue Jun 19, 2012 2:42 am

fishshapedfish wrote:Thanks, If I did that I could even have the crosshair moving with reloads, idle animations and I could even use it with the fire animations and remove the default view offset recoil. On the other hand I would have to recompile all of the hl2 weapons and more so I'll try a different method. I understand that this weapon bob is completely scripted so if I could find this code I could use its values in the crosshair movement.


You don't want the crosshair to move too much. If it moves every time you fire, it will make it really hard to aim, especially if the player is using an automatic weapon.
User avatar
nub
Veteran
Veteran
 
Joined: Tue Nov 15, 2005 1:11 am
Location: Charlotte, NC, US
Next

Return to Programming

Who is online

Users browsing this forum: No registered users