How Bullets Work in Shooter Games
- Hitscan (raycast)
- Game Object
Bullets in video games are usually simulated in two main ways. The most common way is by using hitscans which consist of raycasting from the shooter’s gun in the direction of the shooter’s aiming cursor. The first game object that intersects with this raycast is the object that gets hit by the bullet. This is a cheap method in terms of performance.
The second way bullets are simulated are creating actual bullet game objects in the scene. This way, physics can be applied to the bullet which consist of gravity, material penetration, and most importantly, collision. Collision detection is used to determine if the bullet hits another player by using logic to check the colliding object. This method is expensive performance wise due to more actual game objects and properties being rendered in the scene.
The purpose of this system is to explain how bullets are implemented in video games and show how adding more technical aspects comes with a consequence of slower performance.