Weapon model sway techniques

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Weapon model sway techniques

Post by JasonX »

I'm trying to create an effect similar to the one implemented in TF2: https://www.youtube.com/watch?v=4wPAzutIVpc

And other titles as well: https://www.youtube.com/watch?v=kjVSLsz8dCs

Note that this is not player model bobbing, it's just a subtle effect on the camera and the model itself, slowly reaching the new view target. I could not find any documentation on this topic around the internet and i suspect there's some heavy math behind this and it would be nice if someone here has any idea on how to implement that kind of code. Or, at least, can give me some good directions on the topic. Thanks!
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Re: Weapon model sway techniques

Post by r00k »

darkplaces has something like that

look in the engine source, or the xonotic quakeC source, might have it...
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Weapon model sway techniques

Post by JasonX »

Darkplaces has normal bobbing, applied to the camera, but nothing on weapon model sway.
PrimalLove
Posts: 14
Joined: Sun Oct 19, 2014 2:37 am

Re: Weapon model sway techniques

Post by PrimalLove »

You could make this effect in qc but Darkplaces already has this built into the engine using the cvars cl_leanmodel and cl_followmodel. For more details on these and a few other cvars that let you customize this movement type in console "apropos cl_leanmodel" or "apropos cl_followmodel". It is highly customizable to get the effect you desire. You can even use negative values to change the weapon models react to input movements of the player. No need for qc changes.
Spiney
Posts: 63
Joined: Mon Feb 13, 2012 1:35 pm

Re: Weapon model sway techniques

Post by Spiney »

The Nazi Zombies PSP mod seems to have a pretty nice implementation.

moddb video
hogsy
Posts: 198
Joined: Wed Aug 03, 2011 3:44 pm
Location: UK
Contact:

Re: Weapon model sway techniques

Post by hogsy »

Eukos implemented this for OpenKatana sometime ago, might be worth digging through our code to see how it was done.

https://github.com/OldTimes-Software/Ka ... iew.c#L572

I believe it's all within a function called View_ModelDrift.
Last edited by hogsy on Sat Nov 14, 2015 2:53 pm, edited 1 time in total.
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Weapon model sway techniques

Post by JasonX »

Thanks a lot for the info, guys. The OpenKatana code was very instructive. :D
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Weapon model sway techniques

Post by JasonX »

Implementing a subtle https://en.wikipedia.org/wiki/Lissajous_curve for the bobbing was the way to go. And i was inspired by this video to create the "weapon weight" effect:

https://www.youtube.com/watch?v=ay2SMb9-nEE
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Weapon model sway techniques

Post by mankrip »

Engoo also has a very flexible implementation, with several options.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
JasonX
Posts: 422
Joined: Tue Apr 21, 2009 2:08 pm

Re: Weapon model sway techniques

Post by JasonX »

It's for camera bob, there's no influence on the weapon model based on player input.
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Re: Weapon model sway techniques

Post by r00k »

I have added something like this in Qrack, v_viewmodeldrift # all it does is delay the time the gun moves from when the player changes angles. I'll post some code later but im sure i thought i looked at darkplaces to learn about the effect.
mankrip
Posts: 924
Joined: Fri Jul 04, 2008 3:02 am

Re: Weapon model sway techniques

Post by mankrip »

JasonX: Get the latest version of Engoo. I'm using version 2.77, and in "Options —> View Options" there are options not only for weapon bobbing, but also for weapon following, weapon leaning, weapon drawing and fall bobbing. The "weapon leaning" option is what you're after.

The latest versions of Engoo did add a lot of features everywhere.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
r00k
Posts: 1111
Joined: Sat Nov 13, 2004 10:39 pm

Re: Weapon model sway techniques

Post by r00k »

Code: Select all

/* 
======
View_ModelDrift -- Eukos from OpenKatana
Adds a delay to the view model (such as a weapon) in the players view.
======
*/
void View_ModelDrift(vec3_t vOrigin,vec3_t vAngles,vec3_t vOldAngles)
{
			int	i;
			float	fScale,fSpeed,fDifference;
	static	vec3_t	svLastFacing;
			vec3_t	vForward, vRight,vUp, vDifference;
	
	AngleVectors(vAngles,vForward,vRight,vUp);

	if (host_frametime != 0.0f)
	{
		VectorSubtract(vForward,svLastFacing,vDifference);
		fSpeed = 6.0f;
		fDifference = VectorLength(vDifference);
		
		if ((fDifference > cl_gun_drift.value ))
			fSpeed *= fScale = fDifference/cl_gun_drift.value;
		
		for (i = 0; i < 3; i++)
			svLastFacing[i] += vDifference[i]*(fSpeed*host_frametime);
			VectorNormalize(svLastFacing);

		for (i = 0; i < 3; i++)
		{
			vOrigin[i] += (vDifference[i]*-1.0f)*5.0f;
			vAngles[ROLL] += vDifference[YAW];
		}
	}
}
Post Reply