CHAPTER 08
Intermediate
Projectile and Ballistics Systems
Updated: May 16, 2026
25 min read
# CHAPTER 8
Projectile and Ballistics Systems
1. Introduction
Whether it is an arrow arcing through the sky in *Skyrim* or a laser beam hitting instantly in *Call of Duty*, combat relies heavily on ballistics. Programming a projectile seems simple: spawn an object and move it forward. However, game engines process physics in discrete frames. If a bullet moves too fast, it will pass right through a wall without registering a hit. In this chapter, we will master Projectile and Ballistics Systems. We will explore the critical difference between physical Projectiles and Hitscan (Raycast) weapons, learn how to simulate bullet drop, and trigger physical explosions.2. Learning Objectives
By the end of this chapter, you will be able to:- Differentiate between Hitscan (Raycast) and Physical Projectile systems.
- Implement a Raycast shooting mechanic for instantaneous firearms.
- Instantiate and apply velocity to physical projectiles (rockets/arrows).
- Handle the "Bullet Through Paper" tunneling issue.
- Apply physics-based radial explosion forces to multiple objects.
3. Hitscan Weapons (The Instant Laser)
In fast-paced shooters, standard guns (pistols, rifles) do not shoot physical objects. They shoot a mathematical laser called a Raycast.- How it works: The exact frame the player pulls the trigger, the CPU draws an invisible line forward. If the line intersects a collider, it instantly registers a hit.
- Pros: 100% accurate, no tunneling bugs, extremely cheap for the CPU.
- Cons: No bullet drop, no travel time. (Not good for bows or rocket launchers).
csharp
4. Physical Projectiles (Rockets and Arrows)
For weapons where travel time matters (like a rocket launcher or a sniper rifle with bullet drop), we must spawn a physical GameObject.- 1. Instantiate a Prefab (the missile).
- 2. Grab its Rigidbody.
-
3.
Apply
velocityorAddForce.
-
4.
Let the physics engine handle the arc (gravity) and the impact (
OnCollisionEnter).
csharp
5. Solving the Tunneling Problem
If your physical sniper bullet travels at 800 m/s, it will cover 13 meters in a single frame. If a wall is only 1 meter thick, the bullet will teleport past it.-
The Engine Fix: In the bullet's Rigidbody settings, change "Collision Detection" from
DiscretetoContinuous Dynamic. This forces the engine to mathematically sweep the space between Frame 1 and Frame 2 to ensure it didn't pass through anything. (Warning: This is CPU-intensive!)
6. Explosions (Radial Force)
When a rocket hits a wall, it should push all nearby physics objects away.- 1. Find all objects within a sphere.
- 2. Apply a force originating from the center of the explosion.
AddExplosionForce.
csharp
7. Visual Learning: Hitscan vs Projectile
txt
8. Best Practices
- Fake Bullet Tracers: When using Hitscan, the player still wants to see a bullet. Instantiate a visual "Tracer" particle effect that flies rapidly toward the hit coordinate. The math calculation is already done instantly, but the visual tracer provides the satisfying illusion of a traveling bullet.
9. Common Mistakes
-
Instantiating 100 Bullets a Second: If you are building a minigun using Physical Projectiles, calling
InstantiateandDestroy100 times a second will cause massive Garbage Collection lag. As learned in previous chapters, you MUST use Object Pooling for fast-firing projectile weapons!
10. Mini Project: Build a Grenade
Objective: Spawn an object, delay an explosion, and apply radial force.
csharp
11. Practice Exercises
- 1. What is the definition of a "Hitscan" weapon, and how is it calculated in code?
- 2. What Rigidbody setting must be changed to prevent a fast-moving physical sniper bullet from phasing through walls?
12. MCQs with Answers
Question 1
You are designing a bow and arrow for a medieval RPG. The arrow needs to take 2 seconds to reach the target and arc downward due to gravity. Which ballistics system MUST you use?
Question 2
When writing a Hitscan weapon script using Physics.Raycast, what data is passed back into the out hitInfo variable?
13. Interview Questions
- Q: Contrast the CPU performance cost of an assault rifle using Hitscan Raycasts versus an assault rifle firing 60 Physical Rigidbodies a second.
-
Q: Explain the "Bullet Through Paper" phenomenon (Tunneling). How does setting a Rigidbody to
Continuous Dynamicsolve this, and why don't we use that setting for every object in the game?
- Q: Walk me through the code logic required to create a physics-based explosion. How do you find all the objects affected, and how do you apply the force?