14 ms·
How Do Bullets Work in Video Games?
- jeromebaek 7y agoGreat post! Informative and interesting
- willis936 7y agoCasual games are the ones that use hitscan? Name a single competitive shooter that uses any bullet system other than hitscan.
- detaro 7y agoYes, casual games also use hitscan. Given the sentence follows a paragraph mentioning several other shooters that also at least partially use hitscan, it's fairly clear that they do not claim that only casual games use it. The article also provides examples answering your second demand.
- amarshall 7y agoPUBG is not hitscan. Fornite snipers are not hitscan. I’m sure there are plenty of other examples, but there’s two competitive ones. I would agree though that most FPSs are hitscan, at least for “fast” (e.g. bullets rather than rockets) projectiles.
- jdietrich 7y agoMany of the weapons in Overwatch and all but one weapon in Apex Legends are non-hitscan.
- MattRix 7y agoCorrect. This is perhaps most clearly an intentional design decision with Ana from Overwatch who has a gun that switches from projectile to hitscan depending on whether you are scoped in.
- bszupnick 7y agoI'm not sure the exact definition of "competitive shooter", but I thought Fortnite used a mix, and this old Reddit thread seemed to confirm that. https://www.reddit.com/r/FortNiteBR/comments/73ar5d/the_guns_are_hitscan_and_that_needs_to_be_very/ https://www.reddit.com/r/FortNiteBR/comments/73ar5d/the_guns...
- AntiqueFig 7y agoI think they meant "casual" as opposite of "immersive and realistic" (same sentence in the article), not as "non competitive".
- anonymfus 7y agoI think they meant "casual" in a conventional sense as "easy to get into" as they talk about "simplifying learning curve". So opposite of it is "hard to get into", and "immersive and realistic" is one kind of such games, but not the only one.
- int_19h 7y agoI'm not sure what you mean by "competitive", but there are many non-casual games that don't use hitscan. Off the top of my head, Arma and Red Orchestra.
- keyP 7y agoI think you misinterpreted what was written. > "A lot of “casual” games end up using the hitscan method as it simplifies the learning curve for most beginner players. But what about games that aim to create an “immersive and realistic” shooting experience? They cannot achieve their goals within these constraints. We need to use an alternative method." It's not saying casual games are the only games to use hitscan but it's usually easier and quicker to implement hitscans than projectiles (and more intuitive for casual gamers). Half Life and Halo both use the hybrid system depending on the weapon, as written in the article.
- Dzugaru 7y agoMany competitive shooters use ballistics calculations, Battlefield, Apex Legends to name a few.
- blattimwind 7y agoBF doesn't even have a comp mode built in... are there even any PUG providers for it?
- asutekku 7y agoI would argue that both counter strike and Call of Duty are casual arcade games, despite them being played competitively. Battlefield and Arma instead are not (as) arcadey games and thus do not use hitscan.
- blattimwind 7y agoCS is not an arcade shooter because there is significant mechanical complexity (i.e. skill) to using weapons. Guns in Battlefield are far easier to use in comparison. tl;dr hitscan or not does not correlate with ease of use.
- MattRix 7y agoIs this even true? The only thing "skillful" about CS guns is that they have fixed spray patterns. Otherwise it's very much point and shoot because they're all hitscan. Burst fire weapons (which aren't very popular in CS afaik) take slightly more skill, but still, projectile weapons are objectively more difficult.
- winrid 7y agoSpray patterns as well as different timings for accuracy reset between shots. The skill ceiling is very high...
- od1nos 7y agoAs a high level cs player I would argue that the ingame movement and how it interacts with the gunplay is more important to master than the spray patterns.
- blattimwind 7y ago> The only thing "skillful" about CS guns is that they have fixed spray patterns. Otherwise it's very much point and shoot because they're all hitscan. It's free to play, download it and see for yourself how "point and shoot" weapons in CS are. Slightly less snarky - in CS shooting while moving (as practiced in most other shooters, including BF and CoD) is extremely inaccurate, sometimes comically so (close up, you will miss your opponent, despite your gun barrel visually sticking into their player model). This means that just to fire a gun accurately you require good left/right hand coordination (you move with the left hand, and aim and shoot with the right). For example, you might strafe left to check a corner, register an enemy, you will then flick on their had and synchronize your counterstrafing with your shot. This might sound simple, but the skill ceiling is extremely high. As a long time player of both BF, CoD and CS (all versions) I can tell you that the gunplay of CS is by far the most difficult to master (or rather, get to a half decent level) out of all popular shooters. The time to kill in CS is very low - often zero. > Burst fire weapons (which aren't very popular in CS afaik) take slightly more skill, but still, projectile weapons are objectively more difficult. In most games burst fire weapons are easier to use than their full-auto counterparts, since their bursts are often artificially more accurate than manual bursts
- dkersten 7y agoThings like rockets tend to not be hitscan.
- hatsunearu 7y agothe new call of duty is not hitscan IIRC?
- hoorayimhelping 7y agoOk: Overwatch, Battlefield, PUBG, Escape From Tarkov.
- deleted 7y ago[deleted]
- gcmrtc 7y agoQuake 3 (now Quakelive or Quake Champions): rocket launcher, granade launcher, plasma gun, nail gun.
- deleted 7y ago[deleted]
- keyP 7y agoI'm working on the bullet system for a game right now and another advantage of hitscan I think, that wasn't explicitly mentioned in the article, is that you can get objects behind objects to then determine if the first object should absorb some of the bullet damage. For example, an enemy behind a wall may still damage but not as much as if the shots were fired directly at the player. When you send out the raycast and get a list of all objects hit, you can iterate over the objects hit and reduce damage value until the first enemy object is hit (pending any distance restrictions).
- meheleventyone 7y agoYou can do that when simulating each bullets trajectory as well. For example straightforward setup for collision detection would be a raycast per bullet per tick and as such can work much the same way.
- keyP 7y agoIndeed you can, but the idea is that a raycast is still needed. I should've been more specific in that it doesn't mean the projectile system can't do it but the idea of raycasting allows for that additional advantage cheaply and easily.
- meheleventyone 7y agoYeah the key differentiator is a trade off between cost and simulation fidelity.
- Narishma 7y agoIt is mentioned in the article, with the example of Quake's railgun.
- fulafel 7y agoI wonder if mainstream games will at some point evolve out of the shooting-and-killing focus.
- Grangar 7y agoFIFA, Mario Kart, Pokémon? Mainstream is a lot more than just shooters...
- deleted 7y ago[deleted]
- ben0x539 7y ago(I don't really feel like Pokemon is the best counterexample? The bulk of the game mechanics are still about applying violence to an opponent, it's just mediated by cutesy animals instead of guns and the game stops short of calling the victory condition "killing" because it's for kids.)
- Izkata 7y ago> the game stops short of calling the victory condition "killing" because it's for kids. There is death in the series, end-of-battle fainting is explicitly a different thing (probably better thought of as "knocked unconscious"). The first generation even had the tower in Lavender Town, filled with the graves of dead pokemon. In any case, GP's comment stands: Pokemon is neither a shooter nor focused on killing.
- deleted 7y ago[deleted]
- Ntrails 7y agoIn the way books and films have evolved out of shooting and killing?
- fulafel 7y agoThey never had that focus in the same degree. Count the percentage of time that's violent action in novels/films vs mainstream games, it's nowhere close. Or count the percent of nonviolent titles in yearly critically acclaimed works.
- wrkronmiller 7y agoAre there any good resources for people interested in how multi-player networking/state management works?
- keyP 7y agoIt can be a large topic dependent of the type of game, whether physics and such is involved etc... but I bookmarked this article from before which gave a good overview part 1: https://medium.com/@qingweilim/how-do-multiplayer-games-sync-their-state-part-1-ab72d6a54043 https://medium.com/@qingweilim/how-do-multiplayer-games-sync... part 2: https://medium.com/@qingweilim/how-do-multiplayer-game-sync-their-state-part-2-d746fa303950 https://medium.com/@qingweilim/how-do-multiplayer-game-sync-...
- Hallucinaut 7y agoMight be worth looking at the HN thread about angeldu.st a couple of days ago; lots of discussion and links there about world state
- proaralyst 7y agoHere: https://news.ycombinator.com/item?id=21858226 https://news.ycombinator.com/item?id=21858226
- modernerd 7y agohttps://gafferongames.com/#posts https://gafferongames.com/#posts Specifically: https://gafferongames.com/post/networked_physics_2004/ https://gafferongames.com/post/networked_physics_2004/ https://gafferongames.com/post/what_every_programmer_needs_to_know_about_game_networking/ https://gafferongames.com/post/what_every_programmer_needs_t...
- apk-d 7y agoThis article about networking (as implemented in Source Engine, but applies to most realtime games) is a worthwhile read: https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking https://developer.valvesoftware.com/wiki/Source_Multiplayer_...
- 7y ago
- Tade0 7y agoBack in college I had this course during which we were supposed to design an object-oriented app in Java using concurrency and networking - games were the usual use case. Our professor asked us how would we implement hit detection - there were a few answers, but none touched the underlying idea that when there's no agent(user, AI) input, objects move in a predictable way, so the distance between them is some function of time. For example the distance function of two objects moving in a linear fashion is (IIRC) a squared parabola, so you only need to sample three points in time to get the whole function. And, of course, you only need to recalculate this function for objects that changed direction.
- layoutIfNeeded 7y ago> For example the distance function of two objects moving in a linear fashion is (IIRC) a squared parabola This is only true for points. It’s demonstrably untrue for arbitrary shapes.
- heavenlyblue 7y agoWell, actually it's also true for spheres. Then you can approximate any shape with spheres and use that as an optimisation before actually calculating the more costly distance functions.
- progval 7y agoApproximating a (solid) object with spheres means the spheres are in constant distance and angles with each other. So their trajectories are no longer linear if there is any kind of rotation.
- lonelappde 7y agoWhat is a linear rotation? If one sphere is in linear rotation, why can't two?
- wtallis 7y agoThe point isn't to approximate a solid object as several spheres, but to approximate it with one enclosing sphere. If two objects aren't close enough for their bounding spheres to touch, then you don't need to do a collision detection using the more complicated geometry.
- praptak 7y agoI have played a bullet hell type game (2d) where bullets were actual 2d objects (mostly discs) but the player ship's hitbox was just a point, even though the ship itself was drawn as a somewhat bigger shape. I guess this made the collision detection a bit faster and also made the game more dramatic - the close calls were bullets passing through the ship.
- taneq 7y agoOf course, that's one of those things you can't tell the players. Like that game where the first killing blow (within some timeout) on the player automatically misses. It makes it more fun.
- philipov 7y agoNah, it's actually an explicit conceit in danmaku games (the style described by GP). In Touhou, when you press shift to move slowly, it shows your hitbox as that single point. There's no point in hiding it from the player, because there is no way to even survive if the hitbox weren't a single point. There are often only a few pixels of clearance in between the waves of bullets. Consider this: https://www.youtube.com/watch?v=AY7QEEnSGVU https://www.youtube.com/watch?v=AY7QEEnSGVU EDIT: Or this, https://www.youtube.com/watch?v=JJgy5skcMJI https://www.youtube.com/watch?v=JJgy5skcMJI At the end, you can really see the boss's frustration with the player as the beautifully ordered patterns devolve into an angry display of brute force as she throws every kind of bullet in the game at you at once.
- praptak 7y agoI think it was explicit in the instructions.
- keyP 7y agoIt would be interesting to see if that was a game design decision to allow for the game to be more dramatic. There's something called "Coyote Time" which is named after Wile E. Coyote and him staying in the air for a few seconds before gravity takes effect. Often in platformers, there's an invisible collision box added after cliffs so that if the user was slightly late pressing jump at the edge of the cliff, they would still make it as the invisible collision box would provide an extra step. It's an example of improving gameplay and game feel without being realistic.
- jimbob45 7y agoFlyweights with a recycled object pool I would think.
- mwkaufma 7y agoGood primer, one quibble: ballistics aren't really computationally complex, as the article suggests, but rather _hard to sync over a network_. Local dead-reckoning to compensate for latency, but still ensure all players see the same result (esp e.g. crits like headshots) is thorny.
- sillysaurusx 7y agoThat’s not true though. Bullet trajectories are perfectly predictable. Even something like wind can be known at the time of a bullet firing. It’s no more complicated to sync that than to sync a straight line. ARMA does it. EDIT: If it sounds like I’m saying “syncing bullets is effortless and there are no complications,” you’re reading too much into this. My objection is that bullets are fundamentally easier to sync than players, because they’re perfectly predictable, and you have to sync players already.
- indigochill 7y agoBullet trajectories are predictable. Player movement is not (entirely - but you can usually make educated guesses). How do you determine that within the margin of network latency player A didn't move out of B's bullet trajectory?
- baybal2 7y agoOFP/ARMA family uses parabolas. You need just 2 measurements at 2 time points to calculate a hit. This is also perfectly suited for calculation with SSE in less than a kilocycle. UE does bruteforce calculation as I know.
- Symmetry 7y agoThey also do deflections when you're firing at, e.g., a thin wooden wall a bullet can go through or something hard hit at a shallow angle causing a ricochet.
- sillysaurusx 7y ago
- aeeem 7y agoIt depends on what do you want to use. You can do bullet with raycast or You can simply adding velocity to the bullet or you can move the bullet as projectile in vector 3 and calculate the trajectory of the bullet. You can generate random point inside circle to add error in your final position of the bullet
- casion 7y agoMinor nitpick, the latest Call of Duty uses ballistics on all guns, not hitscan.
- Kapura 7y agoThis is a decent primer, but when it comes to actually implementing projectiles in games, things get more complicated (games are very complex). It’s important to keep performance considerations in mind, and be cognizant of when the performance characteristics change. For instance, if you’re working on a networked game, you have a huge set of constraints on what’s “easy” and what’s “performant” that do not exist in offline games. The projectile code is some of the most complicated in our engine just so that syncing state is consistent. But right now I’m working on a boss fight, so I can optimize some damage code by only checking the projectile’s distance from the player against the projectile radius, instead of doing raycasts through our damage system. I also have more control of which things in the environment can be damaged by projectiles; another example of games being complex with lots of moving parts.
- jtaft 7y agoThey didn't touch upon sound events. Arma for instance you hear sound of the the bullet whizzing by or crashing into an object. After, you hear the sound of the bullet actually being fired (as bullets move faster then sound). This really threw me off at first, but really adds an immersive effect. The farther you are away, the longer the distance between the two sounds.
- themagician 7y agoThat’s cool. Are there other games that do this?
- dogben 7y agocombat flight simulators like DCS and IL2 have this.
- Namrog84 7y agoI play a lot of pubg(player unknowns battlegrounds) and you can often hear the bullet whizzing past you before the initial shot of the gun/rifle/bullet. And you can often gauge how far away someone shot because of this.
- dingaling 7y agoWhich is why more elaborately funded real-World armies are deploying suppressors on line-issue rifles. Without the muzzle report the enemy has a much more difficult task in assessing distance and direction to the source of fire.
- tracer4201 7y agoDisclaimer: not a game programmer so I could be completely wrong. If you’ve implemented hitscan, the easiest implementation would be to find other players within some distance along the ray, and play some sound effect where the intensity of the whizzing sound is a function of the other players distance from the ray. The whizzing sound should provide some sense of direction of the bullet relative to the direction another player is facing. Possibly playing a pre recorded sound from a map of available sounds? Eg a bullet rushing from your 2 o’clock just past your shoulder? Or you could try to mix the sound and create that effect in real time I suppose.
- redistressed 7y agoFun side note to this: although bullet collisions are trivial, sword collisions are genuinely computationally complex, in the sense that I’m not aware of a single publicly available game engine that ships with a robust real-time solver for sword-sword collisions. I find this really interesting because it’s a complete inversion of reality, where bullet impacts are vastly more energetic and chaotic than sword clashes. It tells you something about the scale we play games at, maybe. I don’t see people talking about it, but this has to be a huge part of why sword combat in video games is so much less explored and well-realized than gunfighting. Figuring out why it’s such a hard problem, and exploring the various workarounds and their limitations, is a fun weekend project if you know a little computational geometry. (And it’s probably the work of a few minutes if you know enough formal geometry, I guess.)
- mwkaufma 7y agoGood note!
- phaus 7y agoDo you happen to know what kind of tech Mordhau uses? Its not perfect but the hit detection seems far better than any other melee combat game I've tried.
- meheleventyone 7y agoMordhau uses a lot of raycasts.
- redistressed 7y agoI don’t know specifically, but the general trick is to get your approximate solve to have the impact happen at a consistent time, since that’s what players have fine-grained control over. Other stuff involved in restitution, like angle of deflection and force at the point of impact, you can basically fudge to be close enough for gameplay purposes. If a game feels really satisfying, it generally means that stuff has been tuned really carefully. (So it is with games.) You work that stuff out with numerical accuracy if you can be careful about when you need to, but since the animations and audio cues need to be carefully tuned anyway, it tends to add unnecessary complexity.
- yalogin 7y agoSpeaking as someone who has no knowledge of game programming why is raycasting implemented as a light speed traveling thing? Could they have not done the travel computations on a local buffer and add the effects of gravity or other components and then composite he resultant and rendered to screen? Why does it have to be real time? Too memory hungry for that?
- rriepe 7y agoI think you're confusing raycasting with hitscan. They're very similar. Hitscan does that light-speed-line thing you're describing and instantly delivers a "bullet" along it. Raycasting instead takes the light-speed-line information and runs some process like "What could we do to make this play out convincingly?" Then based on that information, it adds the gravity effects and other stuff to what plays out. You might raycast right before a jump to determine what landing animation your player will ultimately use. That's important during the jump because it makes it look more convincing.
- friendlybus 7y agoRaycasts are cheap because they are just two points with an implied line between. Projectiles are great because they are a basic shape inserted into your preexisting physics sim that handles realistic looking gravity and collisions with everything else that has a collision shape. You could have projectiles ricochet off each other. Precomputing a trajectory loses the dynamics of collision and the cheapness of rays. Fixing projected actions into the future from one point in time can make for weird lag effects and unpredictable results for the player when a moveable piece interrupts a fixed bullet path.
- meheleventyone 7y agoRays are just a geometric primitive defined by a starting point and a direction. So a single raycast based weapon can conceptually fire infinitely far in a single test, so much faster than the speed of light. Collision tests are just the result of calculating the point of intersection between it and other primitives. Games run in discreet time steps called frames or ticks. Bullets travel can then be simulated in several ways for example using numerical integration to apply forces to each bullet for the time step to calculate its new position, collision testing the line segment (“raycasting”) between the position of the last frame and the new position and calculating and displaying the results.
- yomly 7y agoI like how tying physics to FPS is mentioned as an ill-advised thing to do. Destiny 2 not that long ago had an issue with the Cold Heart laser where players on the PC port could output gamebreaking damage by jacking up their FPS as the laser would tick per frame (presumably) so the advice resonated
- ehsankia 7y agoI feel like this is the first thing you learn as a game developer, and it's still mind blowing to me that big games still make this mistakes nowadays. Even in Counter-Strike, back in the days, you'd be slightly more floaty when you cranked your FPS above 150, some went up to 1000 or more.
- mrguyorama 7y agoWhy would that damage be calculated client side?
- yomly 7y agoI have no clue as I was just a player - perhaps the client issued "shot fired" messages tied to frames per second
- tones411 7y agoVery informative. Thank you!
- 6gvONxR4sf7o 7y agoThis doesn’t answer the question I was really hoping to see discusses. The target dot on screen defines a ray from the camera outward. The muzzle isn’t on that ray, nor is it even parallel to it, but the muzzle defines another ray. Which does the bullet follow?
- mAritz 7y agoDepends on the game: Counter-Strike, Quake and most casual games use the crosshair as bullet origin. More simulation focused games like Arma, PUBG, etc. use the actual barrel - some of them also show a bullet intersection marker when you'd hit something very close that your crosshair doesn't cover.
- bullen 7y agoI'm making an action MMO with both ballistic bullets and sword fighting: 1) If you look at how Nintendo solved ping-pong with Wiimote Plus (gyroscope addon) after the obvious letdown of the Wiimote standalone (only accelerometer): they gamified it, there is no 1:1 and the game is still fun. VR prooves this case too, as non-superhuman input is hard to sell after you give a man the mouse! 2) Ballistics are expensive on MMO's because you don't want a proper physics engine on the server. Two solutions I imagined: A) you chunk the projectiles temporal movement as vectors and add those to a 2D array that loops over time and has a limited amount of concurrent bullets per frame. B) You make a distributed voting system where other players detect and report hits to offload the server. For sword fights I think left/right/jump/spin attack should be enough to get the player into the minigame of parrying and attacking interleaved (against many enemies). You just need to work on the abstraction so it's as fast in latency as possible and then make sure it's fun. The most important thing is to not try to simulate reality, reality is boring. Look at how PoP Sands-of-time did it?