4
\$\begingroup\$

To clarify, I've seen this post already

I really like the idea that the chosen answer suggests, yet when I go to implement it the recoil still doesn't "feel" right. The problem is mainly the fact that I'm moving the crosshair instantly to a new location and it feels quite jerky when playing around with it. I think that in order to properly implement recoil I need to move the crosshair more than once over multiple game ticks.

I think the main issue is that many games with realistic recoil "auto re-aim" (if you will) the gun as part of the recoil algorithm. This is from my experiences with various Source Engine games like Garry's Mod and Counter Strike. My best way of describing what I see and thinking about how it is implemented is that a point is chosen with a variance (usually up and slightly right) from the fire coordinates. The gun follows a sort of parabolic path (height depending on velocity of recoil) and eventually gets to the new point.

I'm getting kind of long winded but I hope most of what I said makes sense. Should I attempt to model the recoil implementation in the Source Engine? How would you go about implementing a realistic recoil algorithm? Are there any open source fps game engines that may be able to provide some inspiration?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Whatever you end up with, don't let realism get in the way of fun and whether it feels right from a player's viewpoint. \$\endgroup\$ Commented Oct 1, 2011 at 16:37
  • \$\begingroup\$ I may have worded that wrong or misrepresented my thoughts. When I said realistic I meant in a way that would feel realistic to a player yet in a way that it would still be a "balanced" mechanic in that it wouldn't affect gameplay too much or too little. That is why I'm hesitant to try something like 32bitkid's answer. I will respond back when I have chosen an implementation but right now all the answers have been vague on the actual implementation. I would love if someone was willing to make a response of the quality of 32bitkid's but with a less computationally intensive implementation. \$\endgroup\$
    – Matt
    Commented Oct 5, 2011 at 23:49

3 Answers 3

5
\$\begingroup\$

Just thinking off the top of my head, but a spring model might work well here. You can think of the recoil jolt as being a sort of "particle" in 2D that has a position and velocity, and is attached to the origin by a spring. When the gun is fired you'd give the particle an impulse (i.e. an instantaneous velocity change) up and to the right, then simulate its physics; it would initially move in the direction of the impulse, but the spring would pull it back to the origin. You'll want the spring to have a good deal of damping so that it doesn't oscillate. You can read about simulating a spring online; there are lots of articles about it.

\$\endgroup\$
3
  • \$\begingroup\$ +1 for the spring idea. Sounds really natural, since after a gun kicks you usually end aiming at almost the same position. \$\endgroup\$
    – pek
    Commented Oct 1, 2011 at 5:14
  • \$\begingroup\$ @Pek, what guns have you fired. Maybe if your gun is sighted for targets at 10m will it feel like it returns, but mostly its the skill of the shooter that brings it back on target. \$\endgroup\$ Commented Oct 1, 2011 at 22:53
  • \$\begingroup\$ @Daniel Let's just say that I agree about the skill of the shooter :P \$\endgroup\$
    – pek
    Commented Oct 1, 2011 at 23:35
4
\$\begingroup\$

First, I would recommend stepping away from your computer for a bit. Finding the closest firing range and going there and renting a handgun and actually squeezing off a few rounds to see what it actually feels like.

Even if you have gone shooting before, I would recommend going again, but this time take it from the perspective of an scientist rather than a shooter. Ask the guys there if you can bring in a video camera, and if they are okay with it then set the tripod up right over your right shoulder and pointed down range. Try firing at different speeds, keep your target sheets and mark test cases. When you are all done go back and review the footage of your shots and compare that to your results. I think if you do that you will glean a much better perspective of how this stuff should work.

Second, I would say there are really a couple core attributes involved

  • Kick Strength: The vector kick is actually straight backward from the barrel, not up or in any other direction. The reason a shooters aim drifts up is because you are holding the handle mounted beneath barrel, your arm becomes like lever; your body tries to stay still while the gun tries to move back. As the energy from firing the bullet is diffused into your body, your elbow and shoulder retract and your muscles flex to offset the energy.

  • Player Strength: This works to offset the kick. The stronger you are the less the kick causes your aim to drift. If you were to weld a handgun to the side of a battleship and fire it, its kick would effectively be offset by the mass of the ship. So player strength is inversely related to kick strength.

    Another thing to point out is one vs two handed weapons. While a shotgun or rifle might have a much higer kick than say a medium calibur handgun. Because its stabalized with two hands, your effective strength is much higher. This should be taken in to account. Try (don't try actually) shooting a shotgun single handed and you'll see what I mean.

  • Player Aim: This represents the players ability to hit something they are aiming at. It represented by two components, speed and accuracy. This is manifested in games as the widening reticle widening while moving and the slowly settling when slowed or stopped, but its applicable to post recoil as well.

    But there is another component here that is at play, muscle memory aiming. After you fire, you need to re-aim at your target. But you can usually do it a lot faster than it initially took you to aim because of muscle memory. Using your short-term muscle memory you can reset your aim close, but not perfect, to your intended target. Then from that position you correct your aim over time to get back to your maximum potential to aim.

    This is one of those cases when it helps to go to range. If you focus on your gun sights you will be suprised how much your gun is actually waving around, even when trying to hold it still.

Using these properties, the pseudo-algorthm I would make for gun recoil would look something like this:

  • Use kick_strength - player_strength to determine kick_magnitude
  • apply kick_magnitude to a random up-ish unit vector as kick_aim_position. [To simulate your body diffusing kick_strength]
  • Take initial_aim_position and use muscle_memory_accuracy to determine distance and pick a new point that distance away from your aim as muscle_memory_aim_position. [To simulate re-aiming using muscle memory only.]
  • Lastly settle slowly back to your inital_aim_position. [To simulate correcting your muscle memory with visual input, aiming back at what you want to hit]
\$\endgroup\$
1
  • \$\begingroup\$ Could you be more elaborate with how, you use muscle memory, I'm not understanding it very well... I sense you found the right way to do it though. \$\endgroup\$
    – jokoon
    Commented Mar 15, 2012 at 12:40
0
\$\begingroup\$

The spring model will result in an unrealistic effect. since when a shooter wants to tune his gun after a shot, he slow his movement when he gets near to original target. I'm not sure how my algorithm will turn out but I think it will generate good result:

lets say a player originally targeted point x,y; when he shots, I'll set random values to two new parameters dx,dy; I'll then adjust shooters target to x+dx/(1+time*const_value), y+dy/(1+time*const_value). note that time is calculated from when player shot a bullet.const_value is something based on weapon type. for example for snipe rifle it's something smaller than 1, but for a shotgun it's larger than 1. random value for dx and dy is also based on weapon type, for a snipe it's something small but for shotgun they are big.

\$\endgroup\$

You must log in to answer this question.

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