Bird
Raised Fist0
Unityframework~20 mins

Rigidbody2D component in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the primary purpose of the Rigidbody2D component in Unity?
easy
A. To make 2D objects move and react using physics
B. To display 2D sprites on the screen
C. To handle user input for 2D games
D. To create UI elements in 2D games

Solution

  1. Step 1: Understand Rigidbody2D role

    The Rigidbody2D component applies physics to 2D objects, enabling movement and reactions.
  2. Step 2: Compare with other options

    Options A, B, and D relate to input, sprites, and UI, not physics behavior.
  3. Final Answer:

    To make 2D objects move and react using physics -> Option A
  4. Quick Check:

    Rigidbody2D = physics movement [OK]
Hint: Rigidbody2D controls physics, not visuals or input [OK]
Common Mistakes:
  • Confusing Rigidbody2D with sprite rendering
  • Thinking Rigidbody2D handles input
  • Mixing Rigidbody2D with UI components
2. Which of the following is the correct way to add a Rigidbody2D component to a GameObject in C# script?
easy
A. gameObject.AddComponent<SpriteRenderer>();
B. gameObject.AddComponent<Rigidbody2D>();
C. gameObject.AddComponent<Collider2D>();
D. gameObject.AddComponent<Rigidbody>();

Solution

  1. Step 1: Identify correct component type

    Rigidbody2D is the correct physics component for 2D objects, so use AddComponent<Rigidbody2D>().
  2. Step 2: Check other options

    A adds SpriteRenderer, gameObject.AddComponent<Rigidbody>(); adds 3D Rigidbody, C adds Collider2D, which are different components.
  3. Final Answer:

    gameObject.AddComponent<Rigidbody2D>(); -> Option B
  4. Quick Check:

    Add Rigidbody2D with AddComponent<Rigidbody2D>() [OK]
Hint: Use AddComponent<Rigidbody2D>() for 2D physics [OK]
Common Mistakes:
  • Using Rigidbody instead of Rigidbody2D
  • Adding Collider2D instead of Rigidbody2D
  • Confusing SpriteRenderer with Rigidbody2D
3. Consider this code snippet in Unity C#:
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?
medium
A. The new position after moving 5 units on the x-axis
B. Zero vector (0,0) always
C. An error because velocity cannot be set directly
D. The current position of the Rigidbody2D before moving

Solution

  1. Step 1: Understand Rigidbody2D velocity effect

    Setting velocity changes movement over time, but position updates in the next physics frame, not immediately.
  2. Step 2: Analyze Debug.Log timing

    Debug.Log prints current position instantly, before Rigidbody2D moves, so it shows the original position.
  3. Final Answer:

    The current position of the Rigidbody2D before moving -> Option D
  4. Quick Check:

    Velocity changes future movement, position now = original [OK]
Hint: Velocity changes position next frame, not instantly [OK]
Common Mistakes:
  • Assuming position updates immediately after velocity set
  • Expecting error when setting velocity directly
  • Thinking position always zero
4. You wrote this code to apply a force to a Rigidbody2D:
Rigidbody2D rb = GetComponent<Rigidbody2D>();
rb.AddForce(new Vector2(10, 0));
But the object does not move. What is the most likely reason?
medium
A. AddForce only works with 3D Rigidbody, not Rigidbody2D
B. The force vector is too small to move the object
C. The Rigidbody2D's Body Type is set to Static
D. You need to call rb.MovePosition() instead

Solution

  1. Step 1: Check Rigidbody2D Body Type effect

    If Body Type is Static, physics forces do not move the object.
  2. Step 2: Evaluate other options

    Force vector (10,0) is enough; AddForce works with Rigidbody2D; MovePosition is for manual moves, not force.
  3. Final Answer:

    The Rigidbody2D's Body Type is set to Static -> Option C
  4. Quick Check:

    Static body ignores forces [OK]
Hint: Static Rigidbody2D ignores forces; use Dynamic [OK]
Common Mistakes:
  • Using Static body type expecting movement
  • Thinking AddForce is invalid for Rigidbody2D
  • Confusing MovePosition with AddForce
5. You want to create a 2D game object that moves left and right smoothly using physics and stops instantly when no input is given. Which Rigidbody2D settings and code approach should you use?
hard
A. Set Body Type to Dynamic, use rb.velocity to set horizontal speed, and set velocity to zero when no input
B. Set Body Type to Kinematic, use rb.AddForce to move, and rely on friction to stop
C. Set Body Type to Static, move object by changing transform.position directly
D. Set Body Type to Dynamic, use rb.MovePosition for movement, and ignore velocity

Solution

  1. Step 1: Choose Rigidbody2D Body Type for physics movement

    Dynamic body type allows physics-based movement and velocity control.
  2. Step 2: Use velocity for smooth movement and instant stop

    Setting rb.velocity directly controls speed and can be set to zero to stop immediately.
  3. Step 3: Evaluate other options

    Kinematic bodies don't respond to forces; Static bodies don't move; MovePosition is for manual moves, not smooth physics velocity control.
  4. Final Answer:

    Set Body Type to Dynamic, use rb.velocity to set horizontal speed, and set velocity to zero when no input -> Option A
  5. Quick Check:

    Dynamic + velocity control = smooth move and instant stop [OK]
Hint: Use Dynamic Rigidbody2D and set velocity for smooth control [OK]
Common Mistakes:
  • Using Static or Kinematic body types for physics movement
  • Relying on AddForce without velocity control for instant stop
  • Moving object by transform.position ignoring physics