Skip to content
Game Physics — Collision Detection and Rigid Bodies Explained

Game Physics — Collision Detection and Rigid Bodies Explained

DodaTech Updated Jun 15, 2026 6 min read

Game physics simulates real-world mechanics in virtual environments — objects fall, collide, bounce, and slide. Without physics, every game would need hand-coded movement for every object. Physics engines handle this automatically.

What You’ll Learn

You’ll master collision detection algorithms (AABB, sphere, mesh), rigid body dynamics, raycasting, joints, and physics materials. You’ll build a raycast shooting mechanic in Unity C#.

Why Game Physics Matters

Physics separates toy-like games from immersive ones. The satisfying thud of a grenade landing, the realistic car crash in a racing game, the precise hit detection in a fighting game — all rely on physics. At DodaTech, physics simulation techniques are used in Durga Antivirus Pro for heuristic behavior analysis of suspicious processes.

Game Physics Learning Path

    flowchart LR
  A[Unity/Unreal Guide] --> B[Game Physics]
  B --> C{You Are Here}
  C --> D[Multiplayer Networking]
  C --> E[Game Design]
  style C fill:#f90,color:#fff
  

Collision Detection

Collision detection answers: “Did these two objects touch?” There are several methods with different trade-offs:

Axis-Aligned Bounding Box (AABB)

The simplest method. Each object is enclosed in a rectangle (2D) or box (3D) aligned to the world axes. Two AABBs overlap when their projections overlap on all axes.

bool AABBOverlap(Vector2 aMin, Vector2 aMax, Vector2 bMin, Vector2 bMax)
{
    return aMin.x < bMax.x && aMax.x > bMin.x &&
           aMin.y < bMax.y && aMax.y > bMin.y;
}

Bounding Sphere

Each object has a sphere with center and radius. Two spheres collide when the distance between centers is less than the sum of radii.

bool SphereOverlap(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB)
{
    float dist = Vector3.Distance(centerA, centerB);
    return dist < radiusA + radiusB;
}

Mesh Collision

The most accurate (and expensive). Checks triangle-level intersection. Used for complex terrain and detailed props. In Unity, use MeshCollider with “Convex” enabled for moving objects.

Rigid Bodies

A rigid body component gives an object physics properties:

PropertyEffect
MassHow heavy the object is
DragAir resistance
Angular DragRotation resistance
Use GravityWhether gravity pulls it down
Is KinematicScript-controlled (no physics forces)

Raycasting

Raycasting fires an invisible line and reports what it hits. It’s the backbone of shooting mechanics, interaction prompts, and AI vision:

using UnityEngine;

public class RaycastShooter : MonoBehaviour
{
    public float range = 100f;
    public float damage = 25f;
    public Camera playerCamera;

    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Shoot();
        }
    }

    void Shoot()
    {
        RaycastHit hit;
        Ray ray = playerCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2));

        if (Physics.Raycast(ray, out hit, range))
        {
            Debug.Log("Hit: " + hit.transform.name + " at " + hit.point);

            // Damage the target if it has a health component
            Health targetHealth = hit.transform.GetComponent<Health>();
            if (targetHealth != null)
            {
                targetHealth.TakeDamage(damage);
            }

            // Visual feedback
            Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
        }
    }
}

Expected behavior: Clicking fires a ray from the center of the screen. The ray travels up to 100 units. If it hits something with a Health component, damage is applied. An impact effect spawns at the hit point.

Joints

Joints connect rigid bodies with constraints:

Joint TypeBehaviorUse Case
FixedLocks two bodies togetherWelded objects
HingeRotates around one axisDoors, pendulums
SpringBounces between bodiesSuspension, trampolines
CharacterCapsule-shaped movementPlayer characters

Physics Materials

Physics materials control surface properties:

PropertyEffect
Dynamic FrictionFriction when moving
Static FrictionFriction when stationary
BouncinessHow much energy is retained on bounce
Friction CombineHow friction combines (Average, Min, Max, Multiply)

Common Mistakes Beginners Make

1. Using Mesh Colliders on Moving Objects

Mesh colliders are expensive and cause performance spikes. Use primitive colliders (box, sphere, capsule) for moving objects. Reserve mesh colliders for static geometry.

2. Ignoring Kinematic Bodies

A kinematic rigid body doesn’t respond to forces but can push other objects. Use it for moving platforms and doors that need to affect physics objects.

3. Setting Mass Too Low or Too High

Mass ratio matters more than absolute mass. A mass-1000 object hitting mass-1 creates extreme reactions. Keep masses within 0.1–100 range.

4. Raycasting from the Wrong Origin

Raycast from the camera center for FPS shooters. Raycasting from the weapon model misses because the crosshair may not align with the barrel.

5. Not Using Layer-Based Collision Filtering

Without layer collision matrices, every object checks collision against every other object. Set layers (Player, Enemy, Environment) and disable irrelevant pairs.

6. Overlapping Colliders on Same Object

Two colliders on one object without a rigid body causes undefined behavior. Either add a rigid body or use a single compound collider.

7. Forgetting Continuous Collision Detection

Fast-moving objects (bullets, cars) can pass through thin walls. Enable Collision Detection > Continuous on the rigid body.

Practice Questions

1. What’s the difference between AABB and sphere collision?

AABB uses axis-aligned boxes (cheaper but orientation matters). Spheres use center+radius (orientation-independent, slightly more expensive).

2. What is a raycast?

A raycast fires an invisible line from a point in a direction and returns the first object it intersects.

3. What does a rigid body’s mass affect?

Mass affects how forces (gravity, collisions) affect the object. Heavier objects push lighter ones more.

4. When would you use Continuous collision detection?

For fast-moving objects that could pass through thin geometry between frames.

5. Challenge: Implement a grappling hook.

Fire a raycast. On hit, attach a SpringJoint from the player to the hit point. Pull the player toward it with AddForce. Detach with right-click.

Mini Project: Physics Shooting Gallery

Build a shooting range with physics targets:

  1. Create target objects with Rigidbody and BoxCollider
  2. Write the RaycastShooter script from this tutorial
  3. Add a Health script that destroys targets at 0 HP
  4. Add a PhysicMaterial with bounciness to make targets wobble
  5. Score points for each destroyed target
  6. Add a reset button to respawn targets

FAQ

What is a physics engine?
A physics engine simulates Newtonian mechanics — gravity, collisions, forces — so developers don’t code these systems from scratch.
Which physics engine does Unity use?
Unity uses PhysX (by NVIDIA) for 3D physics and Box2D for 2D physics.
What is continuous collision detection?
CCD checks for collisions between frames by sweeping the collider shape along its path, preventing fast objects from tunneling through walls.

What’s Next

Congratulations on completing this Game Physics tutorial! Here’s where to go from here:

  • Practice daily — Experiment with one physics property per day
  • Build a project — Create a physics-based puzzle game
  • Explore related topics — Vehicle physics, cloth simulation, destructible environments
  • Join the community — Share your physics experiments and get feedback

Remember: every expert was once a beginner. Keep simulating!

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro