| Type | Class (Component) |
|---|---|
| Namespace | UnityEngine |
| Inherits | Component > Object |
| 2D version | Rigidbody2D |
Rigidbody
Adding a Rigidbody hands an object over to the physics engine. It now has mass, falls with gravity, gets pushed by other objects and can be moved with forces. It needs a Collider to actually bump into things.
Without a Rigidbody, your script is a puppeteer holding the object on strings: it goes exactly where you put it. With a Rigidbody, you cut the strings and hand it to the laws of physics. You can still influence it, like kicking a ball (AddForce) or setting how fast it's rolling (linearVelocity), but if you grab it and teleport it (transform.position), physics gets confused.
Properties
| Name | Type | Description |
|---|---|---|
linearVelocity | Vector3 | Current speed and direction in units per second. (Called velocity before Unity 6.) |
angularVelocity | Vector3 | Spin speed, in radians per second. |
mass | float | Weight in kilograms (roughly). Heavier objects need more force to move. Mass doesn't change how fast things fall. |
linearDamping | float | Air resistance. Higher = slows down faster. (Called drag before Unity 6.) |
angularDamping | float | Resistance to spinning. (Called angularDrag before Unity 6.) |
useGravity | bool | Whether gravity affects it. |
isKinematic | bool | If true, physics won't move it; you do, using MovePosition. It still pushes other objects. |
constraints | RigidbodyConstraints | Lock movement or rotation on certain axes, e.g. RigidbodyConstraints.FreezeRotation so a character doesn't tip over. |
interpolation | RigidbodyInterpolation | Set to Interpolate on the player or anything the camera follows, to remove jitter. |
collisionDetectionMode | CollisionDetectionMode | Continuous stops fast objects from passing through walls. Costs more. |
position, rotation | Vector3, Quaternion | The physics engine's own position/rotation for the body. |
Methods
| Method | Returns | Description |
|---|---|---|
AddForce(Vector3 force, ForceMode mode = ForceMode.Force) | void | Push the object. See ForceMode below. |
AddTorque(Vector3 torque, ForceMode mode) | void | Spin the object. |
AddForceAtPosition(force, position) | void | Push at a specific point, which also causes spin (hitting the edge of a crate). |
AddExplosionForce(force, center, radius) | void | Push away from a point, weaker further away. |
MovePosition(Vector3 position) | void | Move to a position during the next physics step. The right way to move kinematic bodies. |
MoveRotation(Quaternion rotation) | void | Rotate during the next physics step. |
Sleep() / WakeUp() | void | Resting bodies "sleep" to save CPU. They wake up automatically when hit. |
ForceMode: which one do I use?
| Mode | Uses mass? | Timing | Good for |
|---|---|---|---|
Force (default) | Yes | Continuous: call every FixedUpdate | Engines, wind, steady pushing |
Acceleration | No | Continuous | Custom gravity, pushing everything equally |
Impulse | Yes | Once, instantly | Jumps, explosions, getting hit |
VelocityChange | No | Once, instantly | Dashes that feel the same for any mass |
Code Samples
Physics-based player with a jump
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PhysicsPlayer : MonoBehaviour
{
[SerializeField] private float moveSpeed = 6f;
[SerializeField] private float jumpForce = 5f;
private Rigidbody rb;
private Vector2 moveInput;
private bool jumpRequested;
void Awake()
{
rb = GetComponent<Rigidbody>();
rb.constraints = RigidbodyConstraints.FreezeRotation; // don't fall over
}
void Update()
{
// 1. Read input in Update (so no key press is missed).
moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
if (Input.GetButtonDown("Jump")) jumpRequested = true;
}
void FixedUpdate()
{
// 2. Apply physics in FixedUpdate.
Vector3 move = new Vector3(moveInput.x, 0f, moveInput.y).normalized * moveSpeed;
// Keep current vertical speed so gravity and jumping still work.
rb.linearVelocity = new Vector3(move.x, rb.linearVelocity.y, move.z);
if (jumpRequested)
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
jumpRequested = false;
}
}
}
[RequireComponent(typeof(Rigidbody))] makes Unity add a Rigidbody automatically when you add this script, and prevents it from being removed.
A moving platform (kinematic)
using UnityEngine;
public class MovingPlatform : MonoBehaviour
{
[SerializeField] private Vector3 offset = new Vector3(0f, 0f, 5f);
[SerializeField] private float speed = 1f;
private Rigidbody rb;
private Vector3 start;
void Awake()
{
rb = GetComponent<Rigidbody>();
rb.isKinematic = true;
start = rb.position;
}
void FixedUpdate()
{
float t = Mathf.PingPong(Time.time * speed, 1f);
rb.MovePosition(start + offset * t);
}
}
What happens at runtime
AddForcedoesn't move anything right away. It adds to a total that's applied during the next physics step.- Each physics step (every
Time.fixedDeltaTimeseconds, 0.02 by default): gravity is added to velocity, forces are converted to velocity changes (dividing by mass where relevant), then position is moved by velocity × time. - The engine checks for overlaps and pushes objects apart, then calls collision messages.
- Unity writes the new position into the Transform. With Interpolate on, the Transform is smoothed between physics steps so it looks fluid at high frame rates.
Common Mistakes
- Moving with
transform.positionortransform.Translate. Skips physics: objects tunnel through walls and collisions are jittery. UselinearVelocity,AddForceorMovePosition. - Calling continuous
AddForcein Update. The push then depends on frame rate. Put it inFixedUpdate. - Old tutorial code doesn't compile. In Unity 6,
rb.velocity→rb.linearVelocity,rb.drag→rb.linearDamping,rb.angularDrag→rb.angularDamping. - Huge mass differences (1 vs 10000) make the simulation unstable. Keep ratios under about 100:1.
See also
This page is a simplified, AI-assisted interpretation. For the complete and authoritative reference, see the official Unity documentation.