🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Weapon recoil as spring?

Started by
5 comments, last by vinnyvicious 5 years, 9 months ago

I was reading CryEngine's codebase, and specifically, the procedural motion bits in the weapon module: https://github.com/CRYTEK/CRYENGINE/blob/26524289c15a660965a447dcb22628643917c820/Code/GameSDK/GameDll/Recoil.cpp

Their recoil implementation is very interesting. It seems to be some sort of spring, applying the effect on the world position of the weapon model (and arms). No IK, no bones, Seems to be the whole object. Does anyone have any material on this subject? Or is this very unique? How everyone else is doing this?

I'm very curious about this kind of thing. They also seem to add a jump bump motion procedurally, as well as sway and movement, but I still haven't found those pieces of code. I'm suspecting a classic Lissajous curve.

Advertisement

Youd netter get a gun and start shooting, you need great damping force to compensate second bend whenever gun is shooting it goes up, muscles compensate that force and gun moves a little bit lower or lets simplify that goes to initial position, anyway you need a damping function so it wont oscillate

From my own experience shooting guns, the gun will push back into your shoulder and the barrel will go upwards (depending on the gun). If you shot a gun in space and had no body to absorb the recoil, it would not act as a spring, but as an instantaneous impulse of force, proportionate to the F=ma equation (using newtons 3rd law of motion). A spring function could be used to approximate the increasing resistance against the human body as the human body gets pushed back and then starts pushing back into the gun until it reaches a resting position. Keep in mind, shooting a gun will put some rotational force on the whole object as well. Some guns, like the M-16A2 will have upward facing vents which slightly counter-act the upward movement, but hand guns will definitely jerk your hand upwards, proportionate to the caliber of bullets being fired. Using video games like Counterstrike for reference models is already very flawed because their gun physics are not reflective of reality.

On 7/31/2018 at 6:29 AM, vinnyvicious said:

How everyone else is doing this?

Personally I use the math formulas for the animation curves. There is this cheat sheet: https://easings.net/ that gives you the names of the curve, then all you need is to Google "CurveName Formula".

I just use the formulas I find on the net, tweak a little bit and use them on the model; using the grip as the centerpoint.

@Scouting Ninja, by using on the model you mean applying the formula on top of delta time and model transforms? Do you use different formulas for rotation, or you just apply on translation? Do you do any IK too?

On 8/10/2018 at 1:18 AM, _WeirdCat_ said:

Youd netter get a gun and start shooting, you need great damping force to compensate second bend whenever gun is shooting it goes up, muscles compensate that force and gun moves a little bit lower or lets simplify that goes to initial position, anyway you need a damping function so it wont oscillate

I'm not trying to emulate the real world, just apply a good "feel" to the weapons without having to animate them individually. I want to procedurally change some generic variables and have a set of those for each weapon in the game. It's not a realistic game at all (arena shooter). I'm just trying to understand how I can use easing formulas and other techniques to juice the whole animation. :)

Sharing some interesting experiments with recoil: https://www.youtube.com/watch?v=E_Aj7Q8R2LA

Sadly, animation is not affected in any way.

This topic is closed to new replies.

Advertisement