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.
| Component | What it does | Without it |
|---|---|---|
| Collider (Box, Sphere, Capsule, Mesh...) | Defines the physical shape. Things can hit it. | Objects pass right through it. |
| Rigidbody | Gives the object mass, velocity and gravity. Physics moves it. | The object stays still unless your code moves it. |
Three kinds of physics objects
| Type | Setup | Use for | Move it with |
|---|---|---|---|
| Static | Collider, no Rigidbody | Floors, walls, level geometry | Don't move it |
| Dynamic | Collider + Rigidbody | Crates, balls, physics-driven players | Forces and velocity (AddForce, linearVelocity) |
| Kinematic | Collider + Rigidbody with Is Kinematic checked | Moving platforms, doors, animated objects that push others | Rigidbody.MovePosition / MoveRotation |
Example: a ball you can push
- Create a Plane (the floor). It already has a Mesh Collider, so it's static.
- Create a Sphere above it. It has a Sphere Collider. Add a Rigidbody.
- 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
- Physics runs on its own clock: by default 50 steps per second (
Time.fixedDeltaTime= 0.02). Your frame rate doesn't change it. - Before each step, Unity calls
FixedUpdateon every script. Your forces are queued. - The physics engine moves every dynamic Rigidbody based on gravity, forces and velocity, and pushes apart anything that overlaps.
- For every pair that touched, Unity calls
OnCollisionEnter/OnCollisionStay/OnCollisionExit(or theOnTrigger...versions) on scripts of both objects. - 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 A | Object B | OnCollision... | OnTrigger... |
|---|---|---|---|
| Static collider | Dynamic Rigidbody | Yes | Yes, if either is a trigger |
| Dynamic Rigidbody | Dynamic Rigidbody | Yes | Yes, if either is a trigger |
| Kinematic Rigidbody | Dynamic Rigidbody | Yes | Yes, if either is a trigger |
| Kinematic Rigidbody | Static collider | No | Yes, if either is a trigger |
| Kinematic Rigidbody | Kinematic Rigidbody | No (by default) | Yes, if either is a trigger |
| Static collider | Static collider | No | No |
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
- Moving a dynamic Rigidbody with
transform.position. This teleports it, skipping physics. It can tunnel through walls and cause jitter. Use forces, velocity orMovePosition. - Mixing 2D and 3D.
BoxCollider2D+Rigidbody(3D) never collide. 2D objects needRigidbody2D, 2D colliders andOnCollisionEnter2D(Collision2D)/OnTriggerEnter2D(Collider2D). - Wrong method signature.
OnCollisionEnter(Collider c)is never called. It must beCollision.OnTriggerEntertakes aCollider. - Fast objects passing through walls. Set the Rigidbody's Collision Detection to Continuous for small, fast things like bullets.
- Non-convex Mesh Collider on a Rigidbody. Dynamic Rigidbodies need Convex ticked on Mesh Colliders. Primitive colliders (box, sphere, capsule) are faster anyway.
- Huge or tiny scale. A 100-unit-tall character falls in slow motion. Keep objects near real-world size (1 unit = 1 meter).
See also
This page is a simplified, AI-assisted interpretation. For the complete and authoritative reference, see the official Unity documentation.