Rage through 32 single player levels and 6 deathmatch levels of sheer terror and fully immersive sound and lighting. Arm yourself against the cannibalistic Ogre, fiendish Vore and indestructible Schambler using lethal nails, fierce Thunderbolts and abominable Rocket and Grenade Launchers.

Post tutorial Report RSS Realistic kickback for the Quake shotgun

Ever wanted to have a good and realistic kickback effect in the Quake weapons? This tutorial shows you how to add it to the normal shotgun, but the code can be easily modded for other weapons as well.

Posted by on - Basic Server Side Coding

Ever wanted to have a good and realistic kickback effect in the Quake weapons? This tutorial shows you how to add it to the normal shotgun, but the code can be easily modded for usage with other weapons as well.

I assume that you've already got the Frikqcc compiler with the quakec source code, and you've got some basic experience with coding at all, so lets go straight to the beggining:

Open up the weapons.qc file and add this function just under the prototypes:

float(float numb) kickback
{
 local float kick; 
 kick = numb * -1; // reverse it
 kick = kick * random(); // randomise it, by multiplying it by a random number from 0 to 1 
 if (kick > -5) kick = -5; // changes the number if its too small
 return kick;
}

As you may have noticed, it isn't possible to modify the player viewangles using .v_angle and the .angles variables, so I've thought of an alternative solution for the problem.

Scroll down to the W_FireShotgun function, and add this code at bottom of it:


msg_entity = self; // send the message to yourself
WriteByte(MSG_ONE,10); // use the protocol 10 , the SVC_SETANGLES protocol, which obviously changes the viewport angles
WriteAngle(MSG_ONE,self.v_angle_x + kickback(12)); // add the kickback to the x axis, the vertical rotation axis
WriteAngle(MSG_ONE,self.angles_y); // the y axis rotates the view horizontaly, we don't want to modify it
WriteAngle(MSG_ONE,0); // reset the z axis, which rolls the view

Basically that's everything, compile the code and observe the effect in Quake :)

Thanks to:
Macvek - my cousin, the original author of the first (buggy) kickback code, which was modified and posted in here by me

Post comment Comments
leilei
leilei - - 5,721 comments

hehe

Reply Good karma Bad karma+1 vote
Bobfan
Bobfan - - 11 comments

nice :-)

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: