0
0
Unityframework~15 mins

Rigidbody forces and velocity in Unity - Deep Dive

Choose your learning style9 modes available
Overview - Rigidbody forces and velocity
What is it?
In Unity, a Rigidbody is a component that makes an object respond to physics. Forces and velocity control how the Rigidbody moves and reacts to the world. Forces push or pull the object, while velocity sets its speed and direction directly. Together, they let you create realistic or controlled motion in games.
Why it matters
Without understanding Rigidbody forces and velocity, game objects would either not move realistically or would behave unpredictably. Forces let you simulate real-world effects like gravity, pushes, or explosions. Velocity lets you control movement precisely. Without these, games would feel lifeless or hard to control.
Where it fits
Before learning Rigidbody forces and velocity, you should know basic Unity concepts like GameObjects and components. After this, you can learn about collision detection, physics materials, and advanced physics interactions like joints or character controllers.
Mental Model
Core Idea
Rigidbody forces push or pull objects over time, while velocity sets their immediate speed and direction.
Think of it like...
Imagine pushing a toy car on the floor: applying a force is like giving it a push that makes it speed up gradually, while setting velocity is like instantly placing it moving at a certain speed.
┌───────────────┐       ┌───────────────┐
│   Rigidbody   │──────▶│   Velocity    │
│   Component   │       │ (speed & dir) │
└──────┬────────┘       └──────┬────────┘
       │                       │
       │                       │
       ▼                       ▼
┌───────────────┐       ┌───────────────┐
│   Forces      │──────▶│  Movement     │
│ (push/pull)   │       │ (position)    │
└───────────────┘       └───────────────┘
Build-Up - 7 Steps
1
FoundationWhat is a Rigidbody in Unity
🤔
Concept: Introduce the Rigidbody component and its role in physics simulation.
A Rigidbody is a Unity component that you add to a GameObject to make it respond to physics. It allows the object to move, fall, and collide naturally. Without a Rigidbody, objects stay still or move only by changing their position manually.
Result
Adding a Rigidbody makes the object affected by gravity and collisions automatically.
Understanding Rigidbody is key because it connects your object to Unity's physics engine, enabling realistic motion.
2
FoundationDifference Between Forces and Velocity
🤔
Concept: Explain the basic difference between applying forces and setting velocity.
Forces are pushes or pulls that change an object's velocity over time, like wind or a push. Velocity is the current speed and direction of the object. You can set velocity directly to move the object immediately, or apply forces to let physics calculate the movement.
Result
You see that forces cause gradual changes, while velocity changes movement instantly.
Knowing this difference helps you decide when to use forces for natural effects or velocity for direct control.
3
IntermediateApplying Forces to Rigidbody
🤔Before reading on: do you think applying a force instantly changes position or velocity? Commit to your answer.
Concept: Learn how to apply forces using Rigidbody methods and how they affect motion.
You can apply forces using Rigidbody.AddForce(Vector3 force). This adds a push in the given direction. The force affects the Rigidbody's velocity over time, causing acceleration. Different force modes control how the force is applied, like ForceMode.Force for continuous push or ForceMode.Impulse for instant push.
Result
The object speeds up gradually or instantly depending on the force mode used.
Understanding force modes lets you create different physical effects, from gentle pushes to sudden impacts.
4
IntermediateSetting Rigidbody Velocity Directly
🤔Before reading on: does setting velocity override forces or combine with them? Commit to your answer.
Concept: Learn how to set Rigidbody velocity directly and how it interacts with forces.
You can set Rigidbody.velocity to a Vector3 value to instantly change the object's speed and direction. This overrides the current velocity, ignoring forces momentarily. This is useful for precise control, like player movement or teleportation effects.
Result
The object moves immediately at the set velocity, ignoring ongoing forces until physics updates.
Knowing that velocity overrides forces helps avoid conflicts and unexpected motion in your game.
5
IntermediateCombining Forces and Velocity Safely
🤔Before reading on: do you think applying forces after setting velocity stacks or resets velocity? Commit to your answer.
Concept: How to use forces and velocity together without causing erratic movement.
When you set velocity directly, it replaces the current velocity. Applying forces afterward adds acceleration on top of that velocity. To avoid conflicts, decide if your object needs physics-driven movement (forces) or scripted movement (velocity). Mixing both requires careful timing and logic.
Result
Smooth, predictable movement that respects both physics and control inputs.
Understanding how forces and velocity interact prevents bugs like jittery or stuck objects.
6
AdvancedEffect of Rigidbody Mass and Drag on Forces
🤔Before reading on: does a heavier Rigidbody move faster or slower when the same force is applied? Commit to your answer.
Concept: Explore how Rigidbody properties like mass and drag affect force and velocity behavior.
Mass determines how much an object resists acceleration; heavier objects need more force to move. Drag slows down velocity over time, simulating air resistance. When you apply a force, the Rigidbody's mass divides the acceleration (Force = Mass × Acceleration). Drag reduces velocity gradually, affecting how forces feel.
Result
Objects with higher mass accelerate slower; drag causes objects to slow down naturally.
Knowing these properties helps you tune realistic or stylized physics responses.
7
ExpertInternal Physics Update and Fixed Timestep
🤔Before reading on: do you think Rigidbody forces update every frame or at fixed intervals? Commit to your answer.
Concept: Understand how Unity's physics engine updates Rigidbody forces and velocity internally.
Unity updates physics in fixed time steps (FixedUpdate), separate from frame rendering. Forces and velocity changes apply during these fixed updates to keep physics stable. Applying forces outside FixedUpdate can cause inconsistent behavior. Rigidbody velocity is integrated over time to update position and rotation.
Result
Physics behaves consistently and smoothly regardless of frame rate variations.
Understanding the fixed timestep prevents common bugs like jittery movement and helps write better physics code.
Under the Hood
Unity's physics engine calculates Rigidbody movement by integrating forces and velocity over fixed time intervals. Forces add acceleration based on mass, changing velocity gradually. Velocity directly sets the speed and direction. The engine then updates the Rigidbody's position and rotation accordingly, resolving collisions and constraints.
Why designed this way?
This design separates physics updates from rendering frames to ensure stable and predictable simulation. Using forces models real-world physics naturally, while velocity allows precise control when needed. The fixed timestep avoids errors from variable frame rates, balancing realism and performance.
┌───────────────┐
│  Forces Input │
└──────┬────────┘
       │
       ▼
┌───────────────┐       ┌───────────────┐
│ Calculate     │──────▶│ Update        │
│ Acceleration  │       │ Velocity      │
└──────┬────────┘       └──────┬────────┘
       │                       │
       ▼                       ▼
┌───────────────┐       ┌───────────────┐
│ Integrate     │──────▶│ Update        │
│ Velocity over │       │ Position &    │
│ Time          │       │ Rotation      │
└───────────────┘       └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does setting Rigidbody.velocity add to current velocity or replace it? Commit to your answer.
Common Belief:Setting Rigidbody.velocity adds to the current velocity, stacking with forces.
Tap to reveal reality
Reality:Setting Rigidbody.velocity replaces the current velocity immediately, ignoring forces until next physics update.
Why it matters:Misunderstanding this causes unexpected jumps or stops in movement when mixing velocity and forces.
Quick: Does applying a force instantly move the Rigidbody's position? Commit to your answer.
Common Belief:Applying a force instantly changes the Rigidbody's position.
Tap to reveal reality
Reality:Applying a force changes velocity over time; position updates happen during physics steps, not instantly.
Why it matters:Expecting instant position change leads to confusion and incorrect timing in game logic.
Quick: Does Rigidbody mass affect how fast an object moves under the same force? Commit to your answer.
Common Belief:Mass does not affect movement speed; all objects move the same under the same force.
Tap to reveal reality
Reality:Mass inversely affects acceleration; heavier objects accelerate slower under the same force.
Why it matters:Ignoring mass leads to unrealistic physics and poor game feel.
Quick: Can you apply Rigidbody forces safely in Update() method? Commit to your answer.
Common Belief:You can apply forces in Update() without issues.
Tap to reveal reality
Reality:Forces should be applied in FixedUpdate() to sync with physics updates; applying in Update() causes inconsistent behavior.
Why it matters:Applying forces in Update() causes jittery or unstable physics, harming gameplay experience.
Expert Zone
1
Applying forces with different ForceModes changes how the physics engine integrates them, affecting gameplay feel subtly.
2
Directly setting velocity can conflict with physics forces, so blending them requires careful state management.
3
Physics timestep settings (Fixed Timestep) impact how smooth and stable Rigidbody motion appears, especially under varying frame rates.
When NOT to use
Avoid using Rigidbody forces and velocity for UI elements or non-physical objects; use direct transform manipulation instead. For character movement, consider using CharacterController or custom kinematic solutions for better control.
Production Patterns
In games, forces simulate natural effects like explosions or wind, while velocity is used for player input or AI movement. Combining both with proper timing and mass tuning creates believable and responsive physics-driven gameplay.
Connections
Newton's Second Law of Motion
Rigidbody forces and velocity directly implement Newton's law (Force = Mass × Acceleration).
Understanding this physics law clarifies why mass affects acceleration and how forces change velocity over time.
Game Loop Architecture
Physics updates run in FixedUpdate, separate from rendering frames in Update.
Knowing the game loop helps synchronize physics and rendering for smooth gameplay.
Control Systems in Engineering
Setting velocity directly is like a control input overriding natural physics forces.
This connection helps understand how manual control and natural dynamics can be balanced in simulations.
Common Pitfalls
#1Applying forces in Update() causing jittery physics.
Wrong approach:void Update() { rigidbody.AddForce(Vector3.forward * 10); }
Correct approach:void FixedUpdate() { rigidbody.AddForce(Vector3.forward * 10); }
Root cause:Physics updates run in FixedUpdate; applying forces in Update causes timing mismatch.
#2Setting velocity every frame ignoring forces leads to unnatural movement.
Wrong approach:void FixedUpdate() { rigidbody.velocity = new Vector3(5, 0, 0); rigidbody.AddForce(Vector3.up * 10); }
Correct approach:void FixedUpdate() { rigidbody.AddForce(Vector3.up * 10); // Avoid overriding velocity directly when using forces }
Root cause:Directly setting velocity overwrites forces, causing conflicts.
#3Ignoring Rigidbody mass when applying forces, causing unrealistic acceleration.
Wrong approach:rigidbody.AddForce(Vector3.forward * 100); // same force for all objects
Correct approach:// Adjust force based on mass rigidbody.AddForce(Vector3.forward * 100 * rigidbody.mass);
Root cause:Not accounting for mass breaks physical realism.
Key Takeaways
Rigidbody forces push or pull objects gradually by changing velocity over time, while velocity sets immediate speed and direction.
Applying forces should be done in FixedUpdate to keep physics stable and consistent.
Setting velocity directly overrides forces temporarily, so mixing both requires careful timing.
Rigidbody properties like mass and drag affect how forces and velocity influence motion, enabling realistic or stylized effects.
Understanding Unity's physics update cycle and Rigidbody mechanics prevents common bugs and helps create smooth, believable movement.