What is a Rigidbody?
- Game Development course
- Beginner
- Lesson 49/83
- 4 min
Learn the role of the Rigidbody component in physics simulation.
What is a Rigidbody?
The Rigidbody component enables a GameObject to be governed by Unity's physics engine (Nvidia PhysX). Adding this component allows the object to move realistically according to gravity, friction, and acceleration.
// Accessing Rigidbody and enabling gravity
Rigidbody rb = GetComponent<Rigidbody>();
rb.useGravity = true;Objects lacking a Rigidbody are treated as static and cannot be pushed or dropped by physics forces.
Mass and Kinematic settings
The mass property on a Rigidbody defines its weight in kilograms. When isKinematic is set to true, the object ignores physics forces and only moves via script or animation.
rb.mass = 2.5f;
rb.isKinematic = false;For example, a moving elevator platform typically uses isKinematic = true so it does not wobble from physical impacts.
Practice Print Rigidbody state
Assign 3 to mass and "Enabled" to gravity. Print Rigidbody Mass: 3 | Gravity: Enabled to the console.
Starter code
using System;
class Program
{
static void Main()
{
// mass ve gravity değerlerini tanımlayıp yazdır
}
}Sample solution
using System;
class Program
{
static void Main()
{
int mass = 3;
string gravity = "Enabled";
Console.WriteLine("Rigidbody Mass: " + mass + " | Gravity: " + gravity);
}
}Expected output
Rigidbody Mass: 3 | Gravity: Enabled
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the primary role of the Rigidbody component in Unity?
- Granting gravity, mass, and physics simulation capabilities to an object Correct answer
- Playing background audio files in an infinite loop
- Calculating the brightness angle of scene light sources
- Only changing the 2D UI pixel resolution of an object
Explanation: Rigidbody brings the object into the physics calculation cycle, providing mass and gravity.
2 Enable gravity
rb.____ = true;
rb.useGravity = true;
Explanation: The useGravity boolean property on Rigidbody is used to toggle gravity.
3 Rigidbody properties
| Term | Meaning |
|---|---|
Rigidbody |
Manages physics simulation — component |
mass |
Object mass in kilograms |
useGravity |
Toggles gravity effect — property |
isKinematic |
Exempts object from physics forces |