Performance: Rigidbody2D component
This affects the physics simulation performance and rendering smoothness of 2D objects in Unity games.
Jump into concepts and practice - no test required
void FixedUpdate() {
rigidbody2D.MovePosition(rigidbody2D.position + Vector2.right * speed * Time.fixedDeltaTime);
}void Update() {
transform.position += new Vector3(1f, 0, 0) * Time.deltaTime;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct transform.position changes | N/A | Causes physics recalculations | N/A | [X] Bad |
| Rigidbody2D.MovePosition in FixedUpdate | N/A | Single physics update per frame | N/A | [OK] Good |
Rigidbody2D component in Unity?Rigidbody2D rb = GetComponent<Rigidbody2D>(); rb.velocity = new Vector2(5, 0); Debug.Log(rb.position);What will be printed in the console immediately after this code runs?
Rigidbody2D rb = GetComponent<Rigidbody2D>(); rb.AddForce(new Vector2(10, 0));But the object does not move. What is the most likely reason?