The Rigidbody2D component lets objects in a 2D game move and react to forces like gravity and collisions, making them behave like real things.
Rigidbody2D component in Unity
Rigidbody2D rb = gameObject.AddComponent<Rigidbody2D>(); rb.gravityScale = 1.0f; rb.mass = 1.0f; rb.velocity = new Vector2(2f, 0f);
You add Rigidbody2D to a GameObject to make it affected by 2D physics.
Properties like gravityScale and mass control how it moves and reacts.
Rigidbody2D rb = gameObject.AddComponent<Rigidbody2D>(); rb.gravityScale = 0; // No gravity rb.mass = 2.0f;
Rigidbody2D rb = GetComponent<Rigidbody2D>(); rb.velocity = new Vector2(5f, 0f);
Rigidbody2D rb = GetComponent<Rigidbody2D>(); rb.AddForce(new Vector2(0f, 10f), ForceMode2D.Impulse);
This script adds a Rigidbody2D to the object, so it falls with gravity. When you press space, it pushes the object up like a jump and prints a message.
using UnityEngine; public class SimpleMover : MonoBehaviour { private Rigidbody2D rb; void Start() { rb = gameObject.AddComponent<Rigidbody2D>(); rb.gravityScale = 1.0f; rb.mass = 1.0f; } void Update() { if (Input.GetKeyDown(KeyCode.Space)) { rb.AddForce(new Vector2(0f, 5f), ForceMode2D.Impulse); Debug.Log("Jump force applied!"); } } }
Remember to add a Collider2D component to detect collisions properly with Rigidbody2D.
Setting gravityScale to 0 makes the object ignore gravity but still respond to forces.
Use ForceMode2D.Impulse for instant pushes, and ForceMode2D.Force for continuous forces.
Rigidbody2D makes 2D objects move and react like real things using physics.
You control movement by changing properties or applying forces.
Combine Rigidbody2D with Collider2D for collision detection and response.