Today we’re looking into the art of pointing a gun at people. Contrary to popular opinion, hitting someone with a projectile several hundred meters out is far more complicated than simply pointing a cross-hair at them.
Spotting the Target
It’s hard to hit what you can’t see. The first step is to spot and identify your target. At a gun range you’re typically shooting well-lit paper targets standing out in the open at a specific range. Unfortunately, real targets aren’t quite that easy to spot. Ambient conditions like poor lighting or heavy rain can make it difficult to see out at a distance. Large animals wandering around in the open may be easy to spot, but intelligent enemies looking to stay hidden will reduce their profile by crouching and use surrounding objects for concealment.
You also typically don’t have the luxury of knowing the exact range to the target. This is important because bullets don’t fly in a straight line, but follow a parabolic trajectory that is further affected by drag forces and crosswinds. Therefore to hit a target further away requires raising the initial angle of the barrel higher. Getting the range wrong can cause your shot to fall short or overshoot.
There are more factors to consider, such as barometric pressure, the distance between sights and bore, and so on. However, given that Ascent of Ashes is not a sniping simulator, most of these are too minute to bother with individually and can be abstracted under an individual survivor’s shooting skill. For target ranging we can reuse the visibility mechanic that already exists within the game: as you gain better vision on a target, your accuracy improves accordingly.
Got you in my sights
Once you have your target, the next step is to line up your sights. First-Person Shooters like to dumb this down to a simple cross-hair and bullets flying in a straight line from the center of the screen. Given that we want skill-based (in)accuracy, that won’t do for us.
We can mathematically determine a maximum angle of inaccuracy easily enough using a formula based on the shooter’s dexterity, shooting skill, their current stance, and so on. However, we don’t want inaccuracy to be a static angle, so we need some way to randomize it. A simple approach commonly used is to have each shot using a random angle within a cone. This works, but leads to very unsatisfying results as shots fired in rapid succession simply fly off into random directions with no rhyme or reason. Instead, we can use a mathematical equation known as a Lissajous figure to determine inaccuracy.
By evaluating our Lissajous curve with the current game time, we can generate a consistent sway pattern for our weapons. That means if you fire multiple shots in a burst, they’ll be grouped roughly within the same area of the pattern, rather than being at opposite ends of a cone. To make sure each gun has its own pattern, we add the weapon’s hash to the current time as a unique offset. It even has some performance benefits as we avoid expensive calls to our pseudo-random number generator.
Managing the Recoil
Those of you who paid attention in physics class know, each action carries an equivalent reaction. As a firearm expels a projectile and high-velocity gases out one end of the barrel, the same force that accelerates them also accelerates the gun into the other direction. This creates a vector of force that forms a fulcrum with the shooter’s shoulder or hands, leading to torque and the muzzle rising upwards.
The physics calculation behind this is fairly complicated, depending on many different factors such from the cartridge’s powder load and burn time, barrel length, grip ergonomics, etc. Fortunately we’re not trying to simulate recoil to the nth degree of accuracy. We can approximate something reasonably close from factors we already track, such as projectile muzzle velocity and weapon mass. After calculating the raw physical forces we get our final muzzle rise by adding a skill component and some randomization to account for the fact the shooter would be acting to bring the muzzle back on target.
While machines can achieve a degree of accuracy far higher than a human, they aren’t perfect either. Even with perfect aim, you will still see some degree of mechanical deviation from individual differences in bullet shape, powder load, barrel condition, etc. While Match ammo is made specifically for high accuracy in competition shooting, buckshot from a shotgun will produce noticeable spread. Fortunately, this is the one case where simple conical deviation is sufficient, and once we apply it we have the final (in)accuracy for our shot.
This wraps up today’s look at accuracy mechanics in Ascent of Ashes. We hope you enjoyed the overview, and we’re looking forward to showing these mechanics in action soon.
Until then, stay safe and keep surviving.