0
0
Unityframework~5 mins

Rigidbody 3D component in Unity

Choose your learning style9 modes available
Introduction

The Rigidbody 3D component lets objects in Unity move and react to forces like gravity and collisions, making them behave like real things.

When you want an object to fall naturally due to gravity.
When you want to push or pull an object with forces.
When you want objects to bounce or collide realistically.
When you want to control an object's movement using physics.
When you want to detect collisions and respond to them.
Syntax
Unity
Rigidbody rb = gameObject.AddComponent<Rigidbody>();
rb.mass = 1.0f;
rb.useGravity = true;
rb.isKinematic = false;

You add Rigidbody to a GameObject to make it physical.

Properties like mass, gravity, and kinematic control how it moves.

Examples
Adds Rigidbody with mass 2 and gravity enabled.
Unity
Rigidbody rb = gameObject.AddComponent<Rigidbody>();
rb.mass = 2.0f;
rb.useGravity = true;
Gets existing Rigidbody and makes it kinematic (not affected by physics).
Unity
Rigidbody rb = GetComponent<Rigidbody>();
rb.isKinematic = true;
Adds Rigidbody and applies an upward force to it.
Unity
Rigidbody rb = gameObject.AddComponent<Rigidbody>();
rb.AddForce(new Vector3(0, 10, 0));
Sample Program

This script adds a Rigidbody to the object so it falls with gravity. When you press space, it pushes the object up like a jump.

Unity
using UnityEngine;

public class SimplePhysics : MonoBehaviour
{
    Rigidbody rb;

    void Start()
    {
        rb = gameObject.AddComponent<Rigidbody>();
        rb.mass = 1.0f;
        rb.useGravity = true;
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(new Vector3(0, 300, 0));
            Debug.Log("Jump force applied!");
        }
    }
}
OutputSuccess
Important Notes

Make sure your object has a Collider component to interact with physics properly.

Setting isKinematic to true stops physics from moving the object, useful for manual control.

Use AddForce to push objects instead of changing position directly for realistic movement.

Summary

The Rigidbody 3D component makes objects move and react like real things using physics.

Add Rigidbody to objects to enable gravity, forces, and collisions.

Control Rigidbody properties to change how objects behave physically.