Performance: Rigidbody forces and velocity
This concept affects the physics simulation performance and frame rendering smoothness in a Unity game.
Jump into concepts and practice - no test required
void FixedUpdate() {
rigidbody.AddForce(new Vector3(5, 0, 0), ForceMode.Force);
}void Update() {
rigidbody.velocity = new Vector3(5, 0, 0);
}| Pattern | Physics Calls | Frame Updates | Jitter Risk | Verdict |
|---|---|---|---|---|
| Direct velocity set in Update | High (every frame) | High (every frame) | High | [X] Bad |
| AddForce in FixedUpdate | Moderate (fixed timestep) | Moderate (fixed timestep) | Low | [OK] Good |
rb in Unity?Rigidbody rb = GetComponent<Rigidbody>(); rb.velocity = new Vector3(0, 5, 0); rb.AddForce(new Vector3(0, 10, 0), ForceMode.Acceleration);What will be the Rigidbody's velocity immediately after these lines run?
Rigidbody rb = GetComponent<Rigidbody>(); rb.velocity += Vector3.up * 5;