Rigidbody and movement
↑Quick overview
Section titled “Quick overview”Rigidbody makes an object participate in Unity’s 3D physics simulation. Use the 2D counterpart Rigidbody2D for 2D physics, which has separate APIs and callbacks. The right movement method depends on whether the object is dynamic, kinematic, or completely nonphysical.
| Task | Typical choice | Why |
|---|---|---|
| Push a dynamic object | AddForce |
Lets the physics solver handle acceleration |
| Control a dynamic body’s velocity | Rigidbody velocity API | Maintains predictable speed when used intentionally |
| Move a kinematic body | MovePosition |
Cooperates with physics movement |
| Move a decorative nonphysical object | Transform |
No Rigidbody solver needed |
A dynamic object
Section titled “A dynamic object”using UnityEngine;
[RequireComponent(typeof(Rigidbody))]public sealed class PushObject : MonoBehaviour{ [SerializeField] private float acceleration = 6f; private Rigidbody body;
private void Awake() => body = GetComponent<Rigidbody>(); private void FixedUpdate() => body.AddForce(Vector3.forward * acceleration, ForceMode.Acceleration);}ForceMode.Acceleration applies acceleration independently of mass. ForceMode.Force takes mass into account, while impulse modes represent instantaneous changes. Choose the mode based on the effect you want rather than adjusting numbers until it feels plausible.
Common mistakes
Section titled “Common mistakes”- Do not teleport a dynamic body every frame using
transform.positionand still expect ordinary collision handling to behave exactly like physics-driven motion. - Use the correct timing. Apply forces from
FixedUpdate; read player input fromUpdateor Input System callbacks. - Check collision layers and colliders. A Rigidbody alone does not guarantee the desired collisions.
- Consider interpolation. A camera can see jitter when graphics update more frequently than physics.
Read the script lifecycle to see why the timing matters.
