Skip to main content
Game Physics – Complete Beginner to Advanced Guide
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
123456789101112
void ShootHitscan()
{
    RaycastHit hit;
    // Shoot a ray 1000 meters forward from the camera
    if (Physics.Raycast(cameraPos.position, cameraPos.forward, out hit, 1000f))
    {
        Console.WriteLine("Hit: " + hit.collider.name);
        // Apply damage to what we hit
        Health target = hit.collider.GetComponent<Health>();
        if (target != null) target.TakeDamage(10);
    }
}

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. 1. Instantiate a Prefab (the missile).
  1. 2. Grab its Rigidbody.
  1. 3. Apply velocity or AddForce.
  1. 4. Let the physics engine handle the arc (gravity) and the impact (OnCollisionEnter).
csharp
123456789101112
public GameObject rocketPrefab;
public float rocketSpeed = 50f;

void ShootProjectile()
{
    // Spawn the rocket
    GameObject rocket = Instantiate(rocketPrefab, gunBarrel.position, gunBarrel.rotation);
    
    // Push it forward
    Rigidbody rb = rocket.GetComponent<Rigidbody>();
    rb.velocity = gunBarrel.forward * rocketSpeed;
}

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 Discrete to Continuous 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. 1. Find all objects within a sphere.
  1. 2. Apply a force originating from the center of the explosion.
Engines provide a built-in method: AddExplosionForce.
csharp
123456789101112131415
void Explode(Vector3 center, float radius, float force)
{
    // Find all colliders within the blast radius
    Collider[] hitColliders = Physics.OverlapSphere(center, radius);
    
    foreach (Collider hit in hitColliders)
    {
        Rigidbody rb = hit.GetComponent<Rigidbody>();
        if (rb != null)
        {
            // Push them away!
            rb.AddExplosionForce(force, center, radius, 1.0f, ForceMode.Impulse);
        }
    }
}

7. Visual Learning: Hitscan vs Projectile

txt
123456789101112
[ HITSCAN (Assault Rifle) ]
Player --------(Instantly hits target on Frame 1)--------> Enemy
*No gravity, no travel time.*

[ PROJECTILE (Arrow) ]
Player
  \ Frame 1
   \ Frame 2
    \ Frame 3 (Gravity pulls it down)
     \
      v Enemy
*Takes 1.5 seconds to arrive. Requires leading the target.*

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 Instantiate and Destroy 100 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
12345678910111213141516171819202122232425262728293031323334
using System.Collections;

class Grenade : MonoBehaviour
{
    public float delay = 3.0f;
    public float blastRadius = 5.0f;
    public float explosionForce = 700f;

    void Start()
    {
        StartCoroutine(ExplodeSequence());
    }

    IEnumerator ExplodeSequence()
    {
        yield return new WaitForSeconds(delay);

        // 1. Find overlapping physics objects
        Collider[] objectsToPush = Physics.OverlapSphere(transform.position, blastRadius);

        // 2. Apply Force
        foreach (Collider obj in objectsToPush)
        {
            Rigidbody rb = obj.GetComponent<Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(explosionForce, transform.position, blastRadius);
            }
        }

        // 3. Delete Grenade
        Destroy(gameObject);
    }
}

11. Practice Exercises

  1. 1. What is the definition of a "Hitscan" weapon, and how is it calculated in code?
  1. 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 Dynamic solve 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?

14. FAQs

Q: Do games like Battlefield use Hitscan or Physical bullets? A: Games with massive open worlds and sniper rifles (like *Battlefield* or *PUBG*) use a hybrid. They shoot a Physical Projectile so it drops over distance, but instead of using a standard Sphere Collider (which might tunnel), the bullet shoots a tiny Raycast forward every frame to check its path.

15. Summary

In Chapter 8, we armed our characters. We learned the fundamental difference in combat architecture between instant Raycast (Hitscan) systems and simulated Rigidbody Projectiles. We explored how to apply continuous collision detection to stop high-speed tunneling glitches. Finally, we learned how to harness the physics engine to calculate radial area-of-effect forces, creating dynamic, chaotic explosions that scatter objects across the room.

16. Next Chapter Recommendation

Our bullets hit walls, but they don't bounce. It is time to dive deep into collision math. Proceed to Chapter 9: Advanced Collision and Physics Responses.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·