0
0
Unityframework~20 mins

Rigidbody2D component in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rigidbody2D Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Rigidbody2D velocity change?

Consider a Rigidbody2D with initial velocity (2, 3). After running the code below, what will be the new velocity?

Unity
Rigidbody2D rb = GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(5, rb.velocity.y);
A(5, 3)
B(2, 3)
C(5, 0)
D(0, 3)
Attempts:
2 left
💡 Hint

Remember that only the x component of velocity is changed.

🧠 Conceptual
intermediate
1:30remaining
Which Rigidbody2D property controls gravity effect?

Which property of Rigidbody2D determines how much gravity affects the object?

AgravityScale
Bmass
Cdrag
DangularVelocity
Attempts:
2 left
💡 Hint

Think about the property that scales gravity force.

🔧 Debug
advanced
2:30remaining
Why does this Rigidbody2D not move as expected?

Given this code, the Rigidbody2D does not move when applying velocity. What is the likely cause?

Unity
Rigidbody2D rb = GetComponent<Rigidbody2D>();
rb.velocity = new Vector2(10, 0);
AThe Rigidbody2D mass is zero
BThe Rigidbody2D has no Collider2D
CThe velocity vector is zero
DThe Rigidbody2D is set to 'Is Kinematic' true
Attempts:
2 left
💡 Hint

Check Rigidbody2D settings that disable physics movement.

📝 Syntax
advanced
1:30remaining
Which code correctly applies a force to Rigidbody2D?

Choose the correct syntax to add a force of (0, 10) to a Rigidbody2D named rb.

Arb.AddForce = new Vector2(0, 10);
Brb.AddForce(new Vector2(0, 10));
Crb.AddForce(Vector2(0, 10));
Drb.AddForce(new Vector3(0, 10, 0));
Attempts:
2 left
💡 Hint

Remember the method signature and vector type for 2D physics.

🚀 Application
expert
3:00remaining
How to freeze Rigidbody2D rotation but allow movement?

You want a Rigidbody2D to move freely but never rotate. Which code snippet achieves this?

Arb.isKinematic = true;
Brb.freezeRotation = true;
Crb.constraints = RigidbodyConstraints2D.FreezeRotation;
Drb.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY;
Attempts:
2 left
💡 Hint

Look for Rigidbody2D constraints that affect rotation only.