Loading lessons...
Rigidbodies & Forces
Rigidbodies & Forces
Unity includes a built-in 3D and 2D physics engine. To make a GameObject behave physically, you need a Rigidbody component.
Rigidbody Component
The Rigidbody component puts a GameObject under the control of Unity's physics engine.
- Gravity: Checking "Use Gravity" makes the object fall down.
- Mass: Defines the weight of the object (higher mass resists force more).
- Drag: Air resistance that slows down movement or rotation.
- Is Kinematic: If checked, the object is NOT affected by forces, gravity, or collisions. It can only be moved manually via script or animation.
Applying Forces in C#
To move a Rigidbody physically, do not set its transform position directly. Instead, apply forces:
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
// Apply upward force
rb.AddForce(Vector3.up * 10f, ForceMode.Force);
}
ForceModes
The ForceMode parameter defines how the force is applied:
Force: Applies a continuous force, using the object's mass (ideal for wind or thrusters).Acceleration: Applies a continuous acceleration, ignoring the object's mass.Impulse: Applies an instant force, using the object's mass (ideal for explosions or jumps).VelocityChange: Applies an instant velocity change, ignoring the object's mass.
TL;DR
- A Rigidbody enables physics forces, velocity, and gravity.
- Kinematic Rigidbodies are immune to physics forces.
- Use
rb.AddForceinsideFixedUpdatefor physics movements. - Select different ForceModes depending on whether the action is continuous or instant.