4
\$\begingroup\$

What would be a good algorithm for calculating the recoil of a shooting guns cross-hairs?

What I've got now, is something like this:

  1. Define min/max recoil based on weapon size
  2. Generate random number of "delta" movement
  3. Apply random value to X, Y, or both of cross-hairs (only "up" on the Y axis)
  4. Multiply new delta based on time from the previous shot (more recoil for full-auto)

What I'm worried about is that this feels rather predicable, what other factors should one take into account when building recoil? While I'd like it to be somewhat predictable, I'd also like to keep players on their toes. I'm thinking about increasing the min/max recoil values by a large amount (relatively) and adding a weighting, so large recoils will be more rare -- it seems like a lot of effort to go into something I felt would be simple.

Maybe this is just something that needs to be fine-tuned with additional playtesting, and more playtesters? I think that it's important to note, that the recoil will be a large part of the game, and is a key factor in the game being fun/challenging or not.

\$\endgroup\$
1
  • \$\begingroup\$ Note that having a predictable spread pattern isn't a bad thing; it gives experienced players a bit of an edge as they learn what to expect. Back before Counter-Strike:Source, if memory serves, the TMP would fire reliably in a sort of figure 8, and you could compensate with practice. Also, note that the recoil for a right-handed shooter (stock on right shoulder) is going to pull up and right for an automatic weapon. \$\endgroup\$
    – ChrisE
    Commented Mar 30, 2011 at 17:28

2 Answers 2

6
\$\begingroup\$

Guns tend to recoil vertically far more than they recoil to the left or right (at least the few I've fired -- pistols and a shotgun -- have done so to the best of my recollection). I have a feeling the random variance in X would just feel unusual.

I would start with an implementation that kicks the gun/view upwards only, probably based on the power of the gun. When fired, a cooldown timer starts. If the gun is fired again while the cooldown timer is still counting down, the vertical kick is applied again, with intensity proportional to how much time is left on the timer. After a certain threshold it might be appropriate to add X axis variance to indicate that the player is really losing control of the (probably automatic) weapon. I've never fired such a thing so I don't know what that is supposed to feel like, but I imagine "chaotic" would fit nicely. The cooldown should probably scale a bit -- but nonlinearly -- as you continue to fire and the intensity of the kicks should probably be similarly damped or smoothed. Pure linear measures might feel too harsh.

Whatever you do, it sounds like your initial plans called for a fair bit of randomization and I don't think that would be appropriate -- a small bit, certainly, but sudden large recoils amidst smaller ones seem like they'd be unusual.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ if you got a Y-axis recoil that depends on teh power of the weapon and the time since last cool down, you could do the same for the x-axis with a smaller value. \$\endgroup\$ Commented Jan 11, 2011 at 12:54
  • \$\begingroup\$ Yeah, I didn't spell it out, but the X axis recoil is much smaller in comparison to the Y axis. But after some thought, I think I agree that the randomization might be detrimental. \$\endgroup\$
    – Nate
    Commented Jan 11, 2011 at 19:23
3
\$\begingroup\$

I'd be tempted to try to approximate real physics here. It isn't something you're going to do several times per frame so the cost of the calc probably won't factor much.

The impulse force of the powder explosion acting along a vector opposite the barrel direction with opposing force vectors where the hands/shoulder are all combine into a linear & angular momentums for the gun.

You vary the mass of the gun, shooter, & the hand/arm strength, along with varying amounts of ammo powers for different recoils. A gun's recoil for a particular person doesn't vary much unless different cartridges are used or the shooter gets fatigued.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .