Documentation

Unity Spark

Open Unity Spark

Unity Spark

Add 2D physics to objects

Make 2D objects fall, collide, and detect triggers with Rigidbody2D and 2D collider components.
Read time 2 minutesLast updated 3 hours ago

Physics makes objects in your game behave like real things. They fall, land on the ground, and bump into each other. Add 2D physics to an object so that it falls, collides with other objects, or detects when something touches it.

Choose components for 2D physics

The following components control physics:
  • A Rigidbody2D component makes an object move with physics. Gravity pulls it down, and other objects can push it.
  • A collider is an invisible shape around the object. Physics uses it to tell when two objects touch. A collider doesn't need to match the sprite exactly. For example, a box around a character is usually enough.
An object needs a collider to bump into anything. It needs a Rigidbody2D component only if physics moves it. The following table shows common setups.

Object

Components

A player or an enemy that falls and jumpsA Rigidbody2D with Body Type set to Dynamic, and a collider.
The ground, walls, and platforms that never moveA collider only.
A moving platform that a script movesA Rigidbody2D with Body Type set to Kinematic, and a collider.
A coin or a checkpoint that the player passes throughA collider with Is Trigger enabled.
2D physics and 3D physics don't interact, so use only 2D bodies and colliders in a 2D game.
To set up physics, ask the AI assistant, for example,
Make the player fall and land on the platforms.

Add a 2D physics component

To add 2D physics to an object:
  1. Select the object in the Hierarchy window.
  2. In the Inspector window, select Add Component.
  3. Expand Physics 2D to list the 2D physics components you can add.
  4. Select the component to add:
    • Add a Rigidbody2D component to use physics to move the object.
    • Add a collider, such as BoxCollider2D or CircleCollider2D, to give the object a shape.

Make a trigger

A trigger is a collider that detects other objects without blocking them. Use a trigger for things the player passes through, such as a coin to collect or a finish line.
To make an object a trigger, enable Is Trigger on its collider.

Keep a player upright

Without a limit, physics can tip a character over when it bumps into a corner.
To stop a player from falling over, enable Z next to Freeze Rotation under Constraints in the Rigidbody2D component.

Additional resources