Today we're going to look at two main techniques used for bullets in games.
What are the principles behind the shooting mechanics in games? What are the ways to make bullets work? How can you add realism by using guns? Let's have a look at two main ways that can be used to set up bullets in games.
It all started with a technique called raycasting that allows game engines to render 3D environments onto 2D images. The same techniques can be used to define which object is intersected by a ray. Back in the days, game developers found another way to use this technique. The idea was to set up a ray in the muzzle of a gun to mimic a bullet. They called this novel approach Hitscan.
What happens when a player shoots? First, the game engine defines the direction your gun is pointing at. Then, the engine casts a ray from the muzzle with a predefined range. Raycasting comes in handy as it lets the engine define whether the initial ray hit an object or not. If the answer is positive and an object is in the line of fire, the engine understands that the target was hit with a bullet.
This approach can also be further enhanced: developers can make the ray hit multiple targets, for example, add a reflective effect to make bullets bounce, make the rays visible, and more.
We're going to discuss a more advanced in a moment, but one of the main things to understand about Hitscan is that the technique is incredibly fast meaning that it won't cost you processing power. It all started with classic Wolfenstein and Doom, but the same technique can still be found in games like Call of Duty and Overwatch (at least some of the guns are based on this approach).
Check out a pack for Unreal featuring 48 assets for ammunition: cartridges, grenades, and boxes.
The technique is cheap and easy to set up, so why would anyone need to developer a different approach. Hitscan bullets are basically rays - they have infinite traveling velocity meaning that they reach the final target in no time which makes it impossible to dodge a bullet. Also, the approach lacks realism, because bullets are usually affected by external forces according to basic physics. You can add sound for a fancier effect, but can't modify what happens between the muzzle and the target.
This is the point that led developers to experiment with Projectile Ballistics. The second approach makes every single bullet a physics object in a game's scene with custom mass, velocity, and other parameters for a game engine to take into account.
One of the most popular examples of using ballistics is Max Payne. Making bullets individual objects in this game allowed the dev team to add the famous Bullet-Time mechanics and achieve the authentic effect of shooting different guns. This approach also allowed developers to add rocket launchers and other fancy guns to the players' arsenal.
The advantages here are quite clear: you can't make a realistic shooter without projectile ballistics as it's a perfect way to add external forces. The Battlefield fans also love this technique as it allows modifying travel time for projectiles, so long-distance shots with sniper rifles feel super realistic as you have to think about the distance between you and your target, the wind, and other factors.
The second approach needs more computational power, of course, because an engine has to define each bullet's position and avoid conflicts. The funny thing is that the projectile method is older compared to Hitscan as there would be no classic arcade games without projectiles.
Have a look at a Unity pack that will let you simulate realistic bullet physics in your games. The pack features a raycast-based system that is capable of dealing with high bullet velocities.
Is there a third way?
Why would one settle with one approach when you can use both of them?! Let's look at Overwatch once again. Soldier 76 and Widowmaker are big Hitscan fans, while characters like Pharah can't imagine their lives without ballistics. Combining two approaches and creating hybrid solutions allows developers to set up different mechanics for players to experiments and master.
Did we miss something in today's post? Discuss the topic and share curios bullet mechanics in the comments.