Performance: Rigidbody 3D component
This affects the physics simulation performance and frame rate smoothness in a 3D game scene.
Jump into concepts and practice - no test required
foreach (var obj in objects) { if (obj.needsPhysics) { obj.AddComponent<Rigidbody>(); obj.mass = 1; obj.useGravity = true; } }
foreach (var obj in objects) { obj.AddComponent<Rigidbody>(); obj.mass = 1; obj.useGravity = true; }
| Pattern | Physics Calculations | CPU Load | Frame Rate Impact | Verdict |
|---|---|---|---|---|
| Adding Rigidbody to all objects | High (all objects simulated) | High | Significant frame drops | [X] Bad |
| Adding Rigidbody only to needed objects | Low (filtered simulation) | Low | Smooth frame rate | [OK] Good |
Rigidbody component to a 3D object in Unity?GetComponent<Rigidbody>() to get Rigidbody on the same GameObject.void Start() {
Rigidbody rb = GetComponent<Rigidbody>();
rb.useGravity = false;
rb.AddForce(new Vector3(0, 10, 0), ForceMode.Impulse);
}
What will happen to the object when the game starts?useGravity = false disables gravity effect on the object.void Update() {
Rigidbody rb = GetComponent<Rigidbody>();
rb.velocity = new Vector3(0, 5, 0);
}
What is the likely problem?useGravity to false and apply upward force every frame disables gravity, so no natural bounce. Set Rigidbody's isKinematic to true and move the ball manually in Update disables physics simulation. Disable Rigidbody and use Transform.Translate to simulate bouncing ignores physics entirely.