Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  ChrisE Mar 30 '11 at 17:28

2 Answers 2

up vote 6 down vote accepted

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.

share|improve this answer
1  
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. –  PATRY Jan 11 '11 at 12:54
    
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. –  Nate Jan 11 '11 at 19:23

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.