Physics Basics

Unity's physics engine makes objects fall, bump into each other and bounce. Two components do the work: a Collider gives an object a shape, and a Rigidbody lets physics move it.

Collider vs. Rigidbody

A Collider is an object's skin: the shape other things can bump into. A Rigidbody is its weight: it hands control to gravity and momentum. A wall has skin but no weight, so it's solid but never moves. A ball has both, so it falls and bounces. A trigger is a laser tripwire: nothing is blocked, but you get an alarm when something crosses it.

ComponentWhat it doesWithout it
Collider (Box, Sphere, Capsule, Mesh...)Defines the physical shape. Things can hit it.Objects pass right through it.
RigidbodyGives the object mass, velocity and gravity. Physics moves it.The object stays still unless your code moves it.

Three kinds of physics objects

TypeSetupUse forMove it with
StaticCollider, no RigidbodyFloors, walls, level geometryDon't move it
DynamicCollider + RigidbodyCrates, balls, physics-driven playersForces and velocity (AddForce, linearVelocity)
KinematicCollider + Rigidbody with Is Kinematic checkedMoving platforms, doors, animated objects that push othersRigidbody.MovePosition / MoveRotation

Example: a ball you can push

  1. Create a Plane (the floor). It already has a Mesh Collider, so it's static.
  2. Create a Sphere above it. It has a Sphere Collider. Add a Rigidbody.
  3. Add this script to the sphere:
using UnityEngine;

public class BallRoller : MonoBehaviour
{
    [SerializeField] private float force = 10f;
    private Rigidbody rb;
    private 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 physics rate.
        rb.AddForce(input * force);
    }
}

What happens at runtime

  1. Physics runs on its own clock: by default 50 steps per second (Time.fixedDeltaTime = 0.02). Your frame rate doesn't change it.
  2. Before each step, Unity calls FixedUpdate on every script. Your forces are queued.
  3. The physics engine moves every dynamic Rigidbody based on gravity, forces and velocity, and pushes apart anything that overlaps.
  4. For every pair that touched, Unity calls OnCollisionEnter / OnCollisionStay / OnCollisionExit (or the OnTrigger... versions) on scripts of both objects.
  5. Unity copies the new Rigidbody positions into their Transforms.

Collisions vs. triggers

Tick Is Trigger on a collider to make it a trigger: things pass through it, but you still get told when they enter. Use triggers for pickups, checkpoints and damage zones.

using UnityEngine;

public class Coin : MonoBehaviour
{
    // Coin: Sphere Collider with Is Trigger ticked.
    // Player: has a Collider and a Rigidbody (or a CharacterController).
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Debug.Log("Picked up a coin!");
            Destroy(gameObject);
        }
    }
}
using UnityEngine;

public class Crate : MonoBehaviour
{
    // A solid collision (neither collider is a trigger).
    void OnCollisionEnter(Collision collision)
    {
        float hitSpeed = collision.relativeVelocity.magnitude;
        if (hitSpeed > 5f)
        {
            Debug.Log("Hit " + collision.gameObject.name + " hard!");
        }
    }
}

When do I get a callback?

Object AObject BOnCollision...OnTrigger...
Static colliderDynamic RigidbodyYesYes, if either is a trigger
Dynamic RigidbodyDynamic RigidbodyYesYes, if either is a trigger
Kinematic RigidbodyDynamic RigidbodyYesYes, if either is a trigger
Kinematic RigidbodyStatic colliderNoYes, if either is a trigger
Kinematic RigidbodyKinematic RigidbodyNo (by default)Yes, if either is a trigger
Static colliderStatic colliderNoNo

Short rule: at least one of the two objects needs a Rigidbody. For solid collisions, it must be a non-kinematic one.

Layers: choosing what collides

Put objects on layers (top of the Inspector, Layer dropdown), then open Project Settings > Physics > Layer Collision Matrix and untick pairs that should ignore each other. For example, player bullets shouldn't hit the player.

Common Mistakes

See also