Physics simulation helps games and apps feel real by copying how things move and interact in the real world.
Why physics simulate realistic behavior in Unity
using UnityEngine; public class PhysicsExample : MonoBehaviour { void Start() { Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>(); rigidbody.mass = 1f; rigidbody.useGravity = true; } }
This code adds a Rigidbody component to an object, which makes it affected by physics.
Rigidbody controls mass, gravity, and how the object moves physically.
using UnityEngine; public class NoGravity : MonoBehaviour { void Start() { Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>(); rigidbody.useGravity = false; // Object will not fall } }
using UnityEngine; public class HeavyObject : MonoBehaviour { void Start() { Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>(); rigidbody.mass = 10f; // Object is heavier } }
using UnityEngine; public class StaticObject : MonoBehaviour { void Start() { Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>(); rigidbody.isKinematic = true; // Object won't move with physics } }
This program shows how adding a Rigidbody changes the object to be affected by physics. It prints the position before and the Rigidbody properties after.
using UnityEngine; public class PhysicsDemo : MonoBehaviour { void Start() { Debug.Log("Before adding Rigidbody:"); Debug.Log($"Position: {transform.position}"); Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>(); rigidbody.mass = 2f; rigidbody.useGravity = true; Debug.Log("After adding Rigidbody:"); Debug.Log($"Mass: {rigidbody.mass}"); Debug.Log($"Use Gravity: {rigidbody.useGravity}"); } }
Physics simulation usually runs every frame to update object positions smoothly.
Adding Rigidbody lets Unity handle forces like gravity and collisions automatically.
Common mistake: forgetting to add Rigidbody means physics won't affect the object.
Use physics simulation when you want natural movement; use manual movement for simple or fixed motions.
Physics simulation makes objects move and interact like in real life.
Adding Rigidbody to objects enables physics effects like gravity and collisions.
Use physics to make games feel more real and fun for players.