Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 36 ยท Physics and Collisions

Rigidbody and Colliders

Learn how Unity physics works: Rigidbody mass, drag and gravity, kinematic bodies, collider shapes, static versus dynamic colliders, moving rigidbodies and runnable overlap tests.

Unity includes a full physics engine (NVIDIA PhysX for 3D, Box2D for 2D). It makes objects fall, collide, bounce and slide without you writing the math. To use it you need to understand two components that work as a pair: the Collider, which gives an object a physical shape, and the Rigidbody, which makes the object move under physics. This lesson explains both, when to use each, and how to move physical objects correctly.

The Unity scripts are read-only. The stand-ins implement simplified overlap tests and a physics step in plain C#, which are the same ideas the engine uses.

Colliders: the shape

A collider is an invisible shape used for collision detection. It does not have to match the visible mesh. The main types:

Collider Best for
BoxCollider Crates, walls, floors, most buildings
SphereCollider Balls, round pickups, quick area checks
CapsuleCollider Characters (smooth on stairs and edges)
MeshCollider Complex static shapes. Must be Convex to be used on a moving Rigidbody
TerrainCollider Unity Terrain
WheelCollider Vehicle wheels

Prefer primitive colliders (box, sphere, capsule) over mesh colliders: they are much cheaper and more stable. For complex objects, combine several primitives as children of one parent (a compound collider). The Scene view draws colliders as green wireframes; edit them with Edit Collider in the Inspector.

Colliders on their own can only be hit; they never move by themselves. A collider with no Rigidbody is a static collider: it works great for floors and walls, but you should not move it every frame, since Unity must rebuild its internal structures.

Rigidbody: the motion

Add a Rigidbody and the physics engine takes control of the object's transform. Its important properties:

Property Meaning
Mass How heavy (default 1). Matters when objects collide with each other
Linear Damping (older: Drag) Air resistance for movement. 0 means none
Angular Damping Resistance to spinning
Use Gravity Whether gravity pulls the object down (9.81 m/s^2 by default)
Is Kinematic The body is moved by your code, not by forces, but still pushes other bodies
Interpolate Smooths motion between physics steps (use on the player or camera target)
Collision Detection Discrete, Continuous, Continuous Dynamic, Continuous Speculative
Constraints Freeze position or rotation on chosen axes (freeze X/Z rotation so a character does not tip over)

Unity 6 renamed drag to linearDamping and velocity to linearVelocity in scripts; older versions use the old names.

Three kinds of bodies

  1. Static collider: collider only. Never moves. Cheap.
  2. Dynamic Rigidbody: collider plus Rigidbody. Moved by forces and collisions.
  3. Kinematic Rigidbody: collider plus Rigidbody with Is Kinematic on. Moved by script (moving platforms, doors); other bodies react to it.

Moving a Rigidbody correctly

Setting transform.position on a Rigidbody object teleports it and ignores collisions along the way. Use the Rigidbody API instead, and do it in FixedUpdate:

C#
using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class BallController : MonoBehaviour
{
    [SerializeField] float force = 12f;
    [SerializeField] float maxSpeed = 8f;
    Rigidbody rb;
    Vector3 input;

    void Awake() { rb = GetComponent<Rigidbody>(); }

    void Update()
    {
        // read input every frame
        input = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
    }

    void FixedUpdate()
    {
        // apply physics at the fixed rate
        rb.AddForce(input * force);
        if (rb.linearVelocity.magnitude > maxSpeed)
            rb.linearVelocity = rb.linearVelocity.normalized * maxSpeed;
    }
}

Other ways to move a body:

  • rb.linearVelocity = v; sets velocity directly (snappy, ignores mass).
  • rb.MovePosition(pos): moves a kinematic body smoothly (or a dynamic one, by teleport-with-interpolation).
  • rb.MoveRotation(q): the rotation version.
  • rb.AddForce(f, mode) and rb.AddTorque(t): see Forces, Physics Materials and Joints.

What the engine does each step

For every dynamic Rigidbody, once per fixed step (default 0.02 s):

  1. add forces (gravity, your AddForce calls) to the velocity,
  2. apply damping,
  3. move the object by velocity times the step,
  4. find overlapping colliders, and push the bodies apart and change their velocities (collision response),
  5. send collision and trigger events to your scripts.

This stand-in does steps 1 to 3 for a ball with damping, plus a floor response, so you can see mass and drag effects.

C# A Rigidbody step with damping (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Without damping the ball falls from 20 meters in about two seconds. With damping it falls more slowly and reaches a steady terminal velocity, just like a real object in air. Mass does not change fall time, but it matters in collisions, as the next lesson shows.

Collision detection: overlap tests

How does the engine know two boxes touch? For axis-aligned boxes the test is simple: they overlap if their intervals overlap on every axis. For spheres, if the distance between centers is less than the sum of the radii. Here are both:

C# Box and sphere overlap tests (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Real engines use these tests inside a broad phase (quickly discard pairs that are far apart using a spatial grid or tree) and a narrow phase (exact tests with rotated boxes, meshes and so on). That is why fewer, simpler colliders make a faster game.

Fast objects and tunneling

A bullet moving at 100 m/s travels 2 meters in one 0.02 s physics step; a thin wall can fall entirely between two steps, so the bullet passes through without a collision: tunneling. Fixes:

  • set the Rigidbody's Collision Detection to Continuous or Continuous Dynamic,
  • make walls thicker,
  • or use raycasts for very fast projectiles (see Raycasting and Layers).

Continuous modes cost more CPU, so enable them only on fast objects.

Common mistakes

  • Moving a Rigidbody with transform.Translate, so it pushes through walls and jitters.
  • Putting a Rigidbody on every object, including scenery.
  • Using non-convex MeshCollider on a moving body (Unity refuses).
  • Changing physics in Update instead of FixedUpdate.
  • Scaling a collider with a parent whose scale is not uniform.
  • Expecting collisions between two objects where neither has a Rigidbody (at least one must have one).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which component makes an object move under the physics engine?

    A Rigidbody hands motion control to the physics engine; a collider only provides shape.
  2. 2. What is a kinematic Rigidbody?

    Kinematic bodies are ideal for moving platforms and doors: scripted motion, physical effects on others.
  3. 3. Where should you call rb.AddForce for continuous movement?

    FixedUpdate is in step with the physics system.
  4. 4. Which setting prevents a fast bullet from passing through a thin wall?

    Continuous detection sweeps the shape between steps so it cannot skip over thin colliders.

Summary

  • Colliders give shape; Rigidbodies give physics motion; a collider without a Rigidbody is static.
  • Prefer primitive colliders; use compound colliders for complex shapes.
  • Move Rigidbodies with forces or linearVelocity in FixedUpdate, never with transform changes.
  • Kinematic bodies are scripted yet push others; use them for platforms.
  • Fast objects need continuous collision detection or raycasts to avoid tunneling.

Next: Collision and Trigger Events