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
Rigidbody forces and velocity
📖 Scenario: You are creating a simple Unity game where a ball moves when forces are applied. You want to control the ball's movement using Rigidbody physics.
🎯 Goal: Build a Unity script that applies a force to a Rigidbody and then reads its velocity to display how fast the ball is moving.
📋 What You'll Learn
Create a Rigidbody variable and assign it in the script
Create a Vector3 force variable with exact values
Apply the force to the Rigidbody using AddForce
Read the Rigidbody's velocity and print it
💡 Why This Matters
🌍 Real World
In many games, objects move realistically using physics forces and velocities. This project shows how to control and monitor that movement.
💼 Career
Understanding Rigidbody forces and velocity is essential for game developers working with Unity to create smooth and realistic object movements.
Progress0 / 4 steps
1
Create a Rigidbody variable
Declare a public variable called rb of type Rigidbody inside the class.
Unity
Hint
Use public Rigidbody rb; inside the class but outside any method.
2
Create a force vector
Create a private variable called force of type Vector3 and set it to new Vector3(0, 300, 0) inside the class but outside any method.
Unity
Hint
Use private Vector3 force = new Vector3(0, 300, 0); inside the class.
3
Apply force to the Rigidbody
Inside the Start() method, apply the force to rb using rb.AddForce(force);.
Unity
Hint
Write a Start() method and call rb.AddForce(force); inside it.
4
Print the Rigidbody velocity
Inside the Update() method, print the velocity of rb using Debug.Log(rb.velocity);.
Unity
Hint
Use Debug.Log(rb.velocity); inside the Update() method to see the velocity in the console.
Practice
(1/5)
1. In Unity, what is the main difference between applying a force to a Rigidbody and setting its velocity directly?
easy
A. Applying a force stops the Rigidbody immediately, setting velocity makes it float.
B. Applying a force changes the Rigidbody's color, setting velocity changes its size.
C. Applying a force disables gravity, setting velocity enables gravity.
D. Applying a force changes velocity gradually, setting velocity changes it instantly.
Solution
Step 1: Understand force effect on Rigidbody
Applying a force adds acceleration, so velocity changes smoothly over time.
Step 2: Understand velocity setting
Setting velocity directly changes speed and direction immediately without gradual acceleration.
Final Answer:
Applying a force changes velocity gradually, setting velocity changes it instantly. -> Option D
Quick Check:
Force = gradual change, velocity = instant change [OK]
Hint: Force pushes smoothly; velocity sets speed instantly [OK]
Common Mistakes:
Thinking force stops the object immediately
Confusing force with color or size changes
Believing velocity affects gravity
2. Which of the following is the correct way to add an upward force to a Rigidbody named rb in Unity?
easy
A. rb.AddForce(Vector3.up * 10);
B. rb.AddForce(10, Vector3.up);
C. rb.AddForce(10);
D. rb.AddForceUp(10);
Solution
Step 1: Check AddForce method signature
Unity's Rigidbody.AddForce expects a Vector3 representing force direction and magnitude.
Step 2: Verify correct usage
Using Vector3.up * 10 applies force upwards with magnitude 10, matching the method signature.
Final Answer:
rb.AddForce(Vector3.up * 10); -> Option A
Quick Check:
AddForce(Vector3) is correct syntax [OK]
Hint: AddForce needs Vector3 direction and magnitude [OK]
A. You cannot use '+=' operator with velocity; it causes errors.
B. This code instantly adds 5 units upward speed every frame, causing acceleration buildup.
C. Vector3.up is not a valid direction for velocity.
D. Rigidbody velocity cannot be changed directly.
Solution
Step 1: Understand velocity += Vector3.up * 5
This adds 5 units upward speed to current velocity instantly each time it runs.
Step 2: Identify problem in repeated calls
If called every frame, velocity keeps increasing, causing unnatural acceleration buildup.
Final Answer:
This code instantly adds 5 units upward speed every frame, causing acceleration buildup. -> Option B
Quick Check:
Adding velocity each frame causes speed to grow too fast [OK]
Hint: Adding velocity each frame causes speed to grow too fast [OK]
Common Mistakes:
Thinking '+=' on velocity causes syntax errors
Believing Vector3.up is invalid
Assuming velocity cannot be changed directly
5. You want to make a Rigidbody jump smoothly using physics forces, but also limit its maximum upward speed to 10 units per second. Which approach correctly combines forces and velocity control?
hard
A. Use rb.AddForce(Vector3.up * jumpForce) only and ignore velocity limits.
B. Set rb.velocity = Vector3.up * 10 directly every frame without forces.
C. Use rb.AddForce(Vector3.up * jumpForce) and clamp rb.velocity.y to max 10 after applying force.
D. Set rb.velocity = Vector3.up * jumpForce once and never apply forces.
Solution
Step 1: Use AddForce for smooth jumping
Applying AddForce lets physics handle smooth acceleration for jump.
Step 2: Clamp velocity to limit max speed
After applying force, clamp rb.velocity.y to 10 to prevent exceeding max upward speed.
Final Answer:
Use rb.AddForce(Vector3.up * jumpForce) and clamp rb.velocity.y to max 10 after applying force. -> Option C
Quick Check:
Force for smooth jump + clamp velocity to limit speed [OK]
Hint: Combine AddForce with velocity clamp to control max speed [OK]
Common Mistakes:
Setting velocity directly every frame causing unnatural jumps
Ignoring velocity limits causing excessive speed
Using only velocity without forces for smooth physics