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.

Pistols and machine guns are easy - you can just have bullets flying in a certain direction, so I already implemented that. A shotgun, on the other hand, does damage to anything in a certain area that looks like a cone. How should I implement that? I have a couple suggestions here, but I could use some advice:

  • Split a bullet in multiple little bullets, that do less damage by themselves, but fly in a similar direction (a closer enemy is more likely to be hit)
  • Not use bullets - just have a particle effect of a shotgun shot and calculate how much damage enemies get based on position/orientation etc.
  • Have a big invisible bullet (a cube for example) that damages things, as well as a particle effect that will make it look like it's actually a shotgun shot.

Thanks in advance!

share|improve this question
    
Those options are all valid (although the first one, why not just start with the multiple bullets?) and the decision is based on your game design. –  congusbongus Sep 20 '13 at 7:14
    
Related: Accuracy vs distance formula and "cone of fire" may be a good search term for this. –  Byte56 Sep 20 '13 at 13:21

1 Answer 1

up vote 21 down vote accepted

Most games implement shotguns as a weapon which fires multiple projectiles at once, but each one with a certain randomization of the angle they leave the actor. In most modern first-person-shooters almost all weapons have at least some spread for every shot they fire to make them less accurate on long range, so the same implementation can be used for shotguns.

Simple implementation: When you want a 10° spread and the player looks into direction 0° vertical and 50° horizontal, the projectiles would leave them in an angle between -5° and +5° vertical and between 45° and 55° horizontal.

Better implementation: Spread the projectiles not in a rectangular but in a circular area around the crosshair of the player.

The perceived reduced efficiency on long range results from the spreading of the projectiles which means that distant and small targets won't be hit by all of them. When you would like to further emphasize this to make your shotgun a pure short-range weapon, you can also reduce the damage of each projectile for every game-logic frame it travels.

In top-down or side-scrolling shooters it is less common to have spread on all weapons because the playing-area is too small for this to make sense, but when you want a weapon like a shotgun this is a different matter and the same technique can be used, just that you don't need to care about the 3rd dimension. Alternatively you could just fire the projectiles in fixed angles Like -6°, -4°, -2°, 0°, 2°, 4°, 6°. In a 2d context it won't look as artificial as in a 3d context and the challenge-gamer will like it, because it reduces chance.

share|improve this answer
    
The better implementation is just as easy. The first approach requires two random angles (horizontal and vertical), as does the second (off-axis [0, +5°] and rotation along axis [0, 360°]) –  MSalters Sep 20 '13 at 10:34
    
@MSalters That does not uniformly distribute the projectiles in the circle. Instead, it concentrates them around the axis. This may or may not be the effect one's going for. To get a uniform random distribution within the circle, see this answer. –  Virtlink Sep 20 '13 at 11:56
    
@Virtlink: right, though uniform probability density inside the circle is not what I'd go for. A normal distribution tends to be best for physics stuff like this, and it's also particulary simple to do: just spread the ϑ values with a 1D normal distribution, and the φ values with the same normal distribution scaled by ϑ. No need to go to doubly-polar coordinates. –  leftaroundabout Sep 20 '13 at 13:00
    
Here is a page discussing shotgun spreads, you might take a look and see what they do. –  AJMansfield Sep 20 '13 at 14:34

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.