Bullets and Beams

I always find myself wanting to do realistic bullets in Unity, why else have a physics engine. We want to see bullets flying in realistic trajectories and leaving unrealistic trails.

The thing is the average bullet, lets say it travels around 1000 m/s, and the actual bullet is probably around 2cm in length and less than 10mm in diameter, is tiny.

Every frame your bullet travels 16.6 meters, and assuming we are not fighting godzilla (106m tall) then it has a good chance to miss an individual target.

The solution to turn up the collision detection so the bullet scans ahead and notices an impact.

Which is great for sniper games or single player campaigns with limited foes, but what about larger battles.

So should we really be starting with a much simpler LOS raycast bullet, or even D20 to hit bullet and only show the tracer as an FX thing.

How do you design a bullet, do you use the same design across lots of games or choose a design based on game and hardware.

And what about Beams, beam lasers in space games, when I use realistic physical beams they look weird as my ship moves the old beams drift off behind the movement path.

41 seconds in…

Yet space games seem to cheat and use fixed lines between the gun and target regardless of relative motion?

Actually how much of modern games is real physical simulation and how much is behind the curtain D20 and lookup tables with FX slapped on top?

And does the Unity Physics sandbox tend to give people new to games the wrong idea on how to design scalable game systems?

Arowx you are much more involved in these subjects than I am at the moment, though I do have a couple thoughts about the subjects in relation to realism and gamey gun shooting.
I think most stuff is faked to make gameplay more enjoyable. Bullet speed is reduced and size is increased in game - compared to real life. Aiming is greatly enhanced and aided and fx is molded, exaggerated and choreographed to provide the player with visual feedback to make the experience more fun/entertaining/visceral.

Being around weapons my entire life in business and recreational - I doubt most people who aren’t avid sporting gun users would enjoy the ‘realism’ of a weapons concussion, recoil, particles of smoke and debris, sound and reaction of real weapons if it was realistically created in game. Add to the experience the tension of actually killing another living being, and real life/death experience where people often are frozen in place with fear or frantically react and end up shooting the family pet accidentally, this experience becomes a much less fun time than how a ‘realistic’ game portrays shooting bullets and killing things.

Players would ultimately complain about too much recoil, too much smoke and debris fx covering the screen, the bullet traveling too fast and not being able to hit anything because they are so used to ‘helper’ bullets and aiming to hit the opponent when they fast aim and shoot from the hip.

It is my opinion that under exaggerating bullet speed and recoil, over exaggerated bullet size and hit detection, finely crafted fx for each weapon to look cool but not mask the view, and extreme aiming aids are all pretty much required to make games enjoyable for the player. There are very few people who would have an enjoyable experience if any games were created to ‘realistically’ represent shooting bullets.

3 Likes

I’m not really clear on what the issue is. Most space games you can’t fly sideways so the bullet trails are never far off-center, and for those where you can, it doesn’t really cause a problem, especially when combined with a high bullet speed. For the demo of my space game kit I think I had them going at 750 m/s. You just have to raycast from the previous position to the current position each frame, and it’s actually more economical the faster they are since they have less screen time before hitting the target or getting out of range.

Here’s an example of a combat situation somewhat similar to yours. Most of the time the bullets are very fast, but at 00:16 you can see a bunch of slower projectiles fired off. I can’t see any issue visually, even though they drift considerably off-center.

https://www.youtube.com/watch?v=HObxSu_9tRw

That’s… exactly the standard way of doing it, isn’t it?

I haven’t looked into this for a looong time, as I haven’t done a shooting game in ages. When I first made one, though, I looked into different ways to implement shooting. There’s two broad approaches.

First is the “hitscan” approach. This is for anything that moves too quickly to be represented as an object in the physics system. If your projectile is likely to regularly hit things in the same tick it is created* this is a good approach. In essence, you use a raycast to detect collision, and then you draw whatever effects you want on top of that afterwards. Each simulation tick you can figure out how far the bullet would have travelled and raycast that distance, so your bullet can still travel over time.

Take note that bullets from conventional guns fired in gravity do not in fact fly in straight lines. With this in mind if you want realistic bullet physics you are not going to do it with the general purpose physics system built into your game engine. One approach is to approximate your bullet’s path as a curve, and then raycast along that curve in multiple steps. The complexity of that curve is entirely up to how much you want to simulate into your trajectory - gravity, wind, shooter motion…

  • A quick search says that an AK47 has a muzzle velocity of ~2350f/s or 715m/s. That’s about 12 meters per frame at 60fps, or twice that at 30fps. With that in mind I would consider any conventional firearm in a video game to be a good fit for this approach.

The second is the “projectile” approach. This is where you create an actual projectile in the game scene and use physics and/or collision detection on it. These will still often move very quickly, so in Unity you’ll probably want to make sure the Rigidbody has continuous and maybe even dynamic collision detection enabled.

Arma does a pretty good job with bullet simulation. I’ve not researched it much but my understanding it’s the most detailed bullet physics simulation you’ll find in a game. I can’t do much searching since I’m in the office, but I would imagine someone has thoroughly studied the techniques used.

1 Like

I used to love a series of WWII simulations called Combat Mission by Battlefront.com. It had very detailed ballistics and even simulated things like the slope and thickness of the different faces of the armor on the tanks and other vehicles, relative to shot trajectories, projectile types and velocities, and a zillion other factors.

It was over the top, but honestly I doubt most people would notice if they hadn’t done all that work and had gone with a more typical generic hit-test.

Wow, that is pretty elaborate.

D20? Raycasts are fine to me if you don’t need bullet-width (e.g. fireball), but if you want to have a travel-time you don’t need to do collider-projectiles already, you can just raycast the same ray for several frames and just check if the target was in the right distance-window for this particular frame.

About your beam-problem, there isn’t much that you can do, only 2 things come to my mind:

  • obscure: bigger muzzle-fx, start the projectile-trail only after a few meters in front of the viewport so the origin is not that obviously off; OR render fake-viewport-anchored trails like you said
  • additive-velocity: add the ships velocity to the muzzle velocity of the shot, changes shooting mechanic of course

For me shooting in games has to be fun, i don’t care much about realism. Fun comes when the feedback feels good:

  • Recoil (pulse-function that smoothly moves my muzzle out of the aimpoint for a fraction of a second after each shoot)
  • CameraKick (kick the camera back after each shot, e.g. Zarya’s weapon in Overwatch does this to my satisfaction)
  • i also like Tracer-lines (i want to know what my bullet does)
  • HitIndication (i want to be notified when my shots hit, but i prefer hit-indication at the impact position instead of the generic overlay on the reticle)
  • Muzzle-FX (Sound, light, flash, barrel-smoke)
1 Like