Page 1 of 1

Weapon model sway techniques

Posted: Fri Jan 09, 2015 12:31 pm
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!

Re: Weapon model sway techniques

Posted: Fri Jan 09, 2015 6:25 pm
by r00k
darkplaces has something like that

look in the engine source, or the xonotic quakeC source, might have it...

Re: Weapon model sway techniques

Posted: Sat Jan 10, 2015 4:03 pm
by JasonX
Darkplaces has normal bobbing, applied to the camera, but nothing on weapon model sway.

Re: Weapon model sway techniques

Posted: Wed Jan 21, 2015 5:23 am
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.

Re: Weapon model sway techniques

Posted: Wed Jan 21, 2015 4:30 pm
by Spiney
The Nazi Zombies PSP mod seems to have a pretty nice implementation.

moddb video

Re: Weapon model sway techniques

Posted: Thu Jan 22, 2015 3:40 pm
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.

Re: Weapon model sway techniques

Posted: Sun Feb 08, 2015 9:54 pm
by JasonX
Thanks a lot for the info, guys. The OpenKatana code was very instructive. :D

Re: Weapon model sway techniques

Posted: Mon Oct 05, 2015 2:18 pm
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

Re: Weapon model sway techniques

Posted: Wed Oct 07, 2015 1:28 am
by mankrip
Engoo also has a very flexible implementation, with several options.

Re: Weapon model sway techniques

Posted: Wed Oct 07, 2015 2:25 am
by JasonX
It's for camera bob, there's no influence on the weapon model based on player input.

Re: Weapon model sway techniques

Posted: Fri Oct 09, 2015 5:57 pm
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.

Re: Weapon model sway techniques

Posted: Fri Oct 09, 2015 11:03 pm
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.

Re: Weapon model sway techniques

Posted: Tue Oct 20, 2015 4:41 am
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];
		}
	}
}