Lesson 3 - Rigidbody, Forces and FixedUpdate

What it means to hand an object to the physics solver: the Rigidbody, the four ForceModes and the numbers they produce, why physics runs on its own clock, and why writing transform.position sends objects through walls.

Subject: Unity Game Engine · 61 slides · code lesson

Open the interactive version of this deck · Homework for this lesson

What this lesson covers

The lesson, slide by slide

1. Rigidbody, Forces and FixedUpdate

Title

Unity - Lesson 3

Handing an object to the solver - and then not fighting it.

2. What you will be able to do

Objectives

This was the lowest score in the diagnostic: 0 out of 3, with an 'I don't know' on FixedUpdate. Nothing here is hard, but all of it is invisible until someone shows you the numbers.

  1. Say what a Rigidbody actually changes about an object, in one sentence
  2. Choose between the four ForceModes and predict the resulting speed
  3. Explain why forces belong in FixedUpdate and input in Update
  4. Predict when writing transform.position will send an object through a wall
  5. Move an object correctly in all three cases: dynamic, kinematic, and no Rigidbody at all

3. What do you already believe?

Warm-up

From memory, before the deck says anything.

Discussion prompt

A cube with a Box Collider sits in the air and does not fall. Write down every explanation you can think of, then say which one you would check first.

Hint: One of your explanations is probably about gravity being off. What would have to exist for gravity to be off?

Answer:

The answer is almost always: there is no Rigidbody. Not 'gravity is disabled' - there is nothing there to disable it on.

Use Gravity is a checkbox on the Rigidbody. No Rigidbody, no checkbox, no simulation, no falling. The Collider is a shape, and a shape does not fall.

4. What a Rigidbody does

Section

Part 1

5. It hands the position over

Concept

Adding a Rigidbody says: from now on, the physics solver decides where this object is. Gravity, forces, collisions and momentum all become its business rather than yours.

Rigidbody — The component that puts an object into the physics simulation. It owns the object's position and rotation from the moment it is added.

That is the whole idea, and every rule in this lesson follows from it. Once the solver owns the position, your job is to ask rather than to set.

Unity Manual - Rigidbody component reference Rigidbody

6. Two hands on the steering wheel

Intuition

Adding a Rigidbody is like handing the wheel to a driving instructor. From then on, grabbing the wheel yourself does not help - you fight each other, and the car goes somewhere neither of you intended.

The instructor is very good. Tell them where to go - 'accelerate', 'turn' - and they handle the road, the other cars, and stopping when something is in the way.

Grabbing the wheel is transform.position = .... Telling them where to go is AddForce, setting the velocity, or MovePosition. Both move the car. Only one of them notices the wall.

7. Collider and Rigidbody are independent

Concept

A Collider is a shape used for contact tests. A Rigidbody is being simulated. Every combination of the two is a real, useful object.

ColliderRigidbodywhat you gettypical use
yesnoa solid shape that never moveswalls, floors, scenery
yesyesfalls, is pushed, is stoppedcrates, balls, ragdolls
noyesfalls through everythingalmost always a mistake
nonoa position with a meshdecorations, empty parents

The first row is most of a level. Realising that most objects want a Collider and no Rigidbody is what stops the habit of adding one to everything.

8. Predict: the wall with a Rigidbody

Prediction

A wall made of a cube with a Box Collider, holding up a level. Someone adds a Rigidbody to it 'so it can collide properly'.

Predict first

What happens when you press Play?

  • Nothing changes - walls are heavy
  • The wall falls
  • The wall becomes solid where it was not before
  • Unity warns that walls should not have Rigidbodies

Correct: The wall falls, and probably tips over.

Why: A Rigidbody does not mean 'collides better' - it means 'is simulated', and a simulated object with nothing under it falls. Static scenery is solid because of its Collider, and it stays put precisely because it has no Rigidbody.

9. Rigidbody or not?

Sorting

Sort these game objects by whether they need one.

Sort into buckets

Which need a Rigidbody?

Needs a Rigidbody
A crate the player can push; A thrown grenade; A ragdoll body part
Collider only
The ground; A locked door that never moves; A coin that spins on the spot and is collected
yes
The simulation has to move it: it falls, is pushed, tumbles or is thrown. If gravity or a force should affect it, it needs one.
no
It never moves under physics. The coin is the interesting case - it spins because a script rotates it, and it is collected by a trigger, so nothing about it needs simulating.

10. Reading a Rigidbody's settings

Worked example

Five fields on the component decide almost everything. Here they are set from code so the names are visible.

Rigidbody body = GetComponent<Rigidbody>();
body.mass = 1f;                  // kilograms; matters for Force and Impulse
body.useGravity = true;          // the checkbox people look for on the Collider
body.isKinematic = false;        // true = "I drive, physics does not push me"
body.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
fieldmeanswhen to change it
masshow hard it is to acceleraterelative sizes matter; absolute values rarely do
useGravityis it pulled downoff for projectiles with their own arc, top-down games
isKinematicphysics does not move it, but it is still a physics objectmoving platforms, lifts, scripted doors
collisionDetectionModediscrete check vs swept checkanything fast - the fix for tunnelling
linearDamping / draghow quickly it slows on its ownto stop things sliding forever

11. Why does isKinematic exist?

Explain it to yourself

Discussion prompt

A kinematic Rigidbody is not pushed by forces and ignores gravity. So why add one at all - why not just have no Rigidbody?

Hint: Think about a lift carrying a crate, and about what the crate needs to know.

Answer:

Because it is still in the simulation. Other bodies collide with it correctly, it can push them, and it fires trigger callbacks - all of which a plain static collider does far less well when it moves.

A moving platform with no Rigidbody is a static collider that teleports every frame: things standing on it fall through, and the solver has to rebuild its static structures constantly. A kinematic Rigidbody moved with MovePosition is the supported way to say 'this moves, but I decide how'.

12. Forces and the four ForceModes

Section

Part 2

13. AddForce is a request, not a move

Concept

AddForce does not move anything. It adds to the forces acting on the body this physics step; the solver then works out the resulting velocity and position.

void FixedUpdate()
{
    body.AddForce(Vector3.forward * 10f, ForceMode.Force);
}
you callthe solver does
AddForce(f, Force)acceleration = f / mass, applied for this 0.02s step
nothing elseintegrates velocity, then position
nothing elsechecks what is in the way, resolves contacts
nothing elsewrites the new transform, once, at the end

Unity Scripting API - Rigidbody.AddForce Rigidbody.AddForce

14. Four modes, two questions

Concept

The four ForceModes are not four strengths. They are the four answers to two independent yes/no questions.

ForceModespread over time?divided by mass?think of it as
Forceyesyesan engine pushing
Accelerationyesnogravity - same for everything
Impulsenoyesa hammer blow
VelocityChangenono'be going this fast, now'

Unity Scripting API - ForceMode ForceMode

15. Predict before the trace

Prediction

Mass 1, fixed timestep 0.02s, AddForce(Vector3.forward * 10, ForceMode.Force) every FixedUpdate.

Predict first

What is the sphere's speed after the FIRST physics step?

  • 10 m/s
  • 0.2 m/s
  • 0.5 m/s
  • It depends on the frame rate

Correct: 0.2 m/s.

Why: Force means 'this many newtons, applied continuously'. Acceleration is force over mass: 10 / 1 = 10 m/s squared. One step is 0.02s, so the speed gained is 10 x 0.02 = 0.2 m/s. It keeps gaining 0.2 every step for as long as you keep pushing.

16. The force trace, six steps

Worked example

This is the lab's output, with four spheres pushed by 10 units in each of the four modes.

void FixedUpdate()
{
    if (continuous)                       // Force, Acceleration
        body.AddForce(Vector3.forward * pushStrength, mode);
    else if (!fired)                      // Impulse, VelocityChange
    {
        fired = true;
        body.AddForce(Vector3.forward * pushStrength, mode);
    }
}
fixed stepForceAccelerationImpulseVelocityChange
10.200.2010.0010.00
20.400.4010.0010.00
30.600.6010.0010.00
40.800.8010.0010.00
51.001.0010.0010.00
61.201.2010.0010.00

Read the columns in pairs

Why: Force and Acceleration climb because they are applied every step. Impulse and VelocityChange jump once and then flatten, because they were applied once.

With mass 1 the left pair and the right pair look identical. The next slide is where they separate.

17. Change the mass and watch what does not move

Invariant

Same four spheres, same push of 10, but mass = 2. Step through and find the two columns that did not change.

Step through it

Two of these four are unchanged by doubling the mass. Which, and what does that tell you?

  1. mass 1
  2. mass 2
  3. mass 4

Acceleration and VelocityChange ignore mass. They describe the result you want. Force and Impulse describe the push you are making, and a heavier object does less with the same push - which is Newton, not Unity.

18. Pick the mode, do not compute

Discrimination

For each requirement, choose which of the two families it belongs to. Do not work out numbers.

Sort into buckets

Continuous push, or one-shot?

Force / Acceleration (every step)
A rocket burning while the thruster is held; Wind blowing across the level
Impulse / VelocityChange (once)
A jump when the button is pressed; A bat hitting a ball
cont
The push lasts for a while, so it is applied every FixedUpdate for as long as it lasts. These are multiplied by the timestep internally, which is why you do NOT also multiply by Time.fixedDeltaTime yourself.
once
The push happens at one instant. Apply it in a single call, guarded so it cannot fire again next step - the commonest jump bug is a jump impulse applied every step while the key is held.

19. Trap: multiplying a force by deltaTime

Trap

The trap

Everything else is multiplied by delta time, so a force should be too.

void FixedUpdate()
{
    body.AddForce(direction * speed * Time.fixedDeltaTime, ForceMode.Force);
}

The result is a push 50 times weaker than intended, so you compensate by raising speed to 500, and now nothing in the Inspector means anything.

The fix

ForceMode.Force and ForceMode.Acceleration are already per-second quantities. The solver multiplies by the timestep for you.

void FixedUpdate()
{
    body.AddForce(direction * speed, ForceMode.Force);      // no deltaTime
}
what you are writingmultiply by deltaTime?
AddForce with Force or Accelerationno - the solver does it
AddForce with Impulse or VelocityChangeno - they are instantaneous by definition
transform.position += in Updateyes - always
transform.Rotate in Updateyes - always

20. Complete the jump

Fill the middle

A jump: one upward push, only when grounded, in the right callback.

Fill in the blanks

void Update()
FixedUpdate

void Impulse()
___});
}
}

Why: Input is read in Update because a key press can happen on any frame and would be missed between physics steps; the force is applied in FixedUpdate because that is where the solver is listening. Impulse is the one-shot that respects mass, which is what you want if a heavy character should not leap as high; VelocityChange is defensible when every character should jump identically regardless of mass.

21. The two clocks

Section

Part 3

22. Update runs per frame; FixedUpdate runs per physics step

Concept

Figure (svg): Two timelines: an irregular Update timeline above a perfectly regular FixedUpdate timeline

Two clocks. Only one of them is yours to rely on.

Update is called once per rendered frame - as often as the machine manages, and never the same number of times twice. FixedUpdate is called on the physics clock: a fixed slice of simulated time, by default 0.02 seconds, 50 times per simulated second.

Unity Manual - Order of execution for event functions Order of execution

23. Counting both, for two seconds

Worked example

The lab counts each callback over a fixed window and prints the rates.

void Update()      { updateCalls++; }
void FixedUpdate() { fixedCalls++; }
// after 2 seconds:
//   Update ran 287 times (144 per second)
//   FixedUpdate ran 100 times (50 per second)
machineUpdate per secondFixedUpdate per secondphysics stays correct?
gaming PC14450yes
laptop6050yes
struggling build2050yes - 2-3 steps per frame
paused (timeScale 0)still runs0n/a - the simulation is stopped

The third row is the one that matters. At 20 fps, FixedUpdate runs two or three times per frame - so code in Update that pushes 'once per frame' pushes at a third of the rate it did at 60 fps.

24. Predict: the force in the wrong callback

Prediction

A developer puts AddForce(forward * 10, ForceMode.Force) in Update instead of FixedUpdate. It feels right on their machine.

Predict first

What does a player on a 30 fps machine experience?

  • The same speed - forces are frame-rate independent
  • Half the acceleration of the 60 fps machine
  • Double the acceleration
  • A crash

Correct: Roughly half the acceleration - the object accelerates faster on faster machines.

Why: The force is applied once per Update call, so half the frames means half the pushes. This is the bug that gets reported as 'the game is too hard on my laptop', is not reproducible on the developer's machine, and is invisible in code review unless you know to look at which callback it sits in.

25. Trap: physics in Update

Trap

The trap

Everything else is in Update, so this is too.

void Update()
{
    if (Input.GetKey(KeyCode.W))
        body.AddForce(transform.forward * speed, ForceMode.Force);
}
frame ratepushes per secondresulting speed
144 fps144fast
60 fps60the tuned speed
30 fps30sluggish

The fix

Read input where input happens; apply force where the solver is listening. The flag is the bridge.

bool thrusting;

void Update()                       // every frame: never miss a key
{
    thrusting = Input.GetKey(KeyCode.W);
}

void FixedUpdate()                  // every physics step: exactly 50 a second
{
    if (thrusting)
        body.AddForce(transform.forward * speed, ForceMode.Force);
}
read in Updateact in FixedUpdate
Input.GetKeyDown (one frame only)set a bool, clear it after acting
Input.GetKey (held)read the bool each step
mouse position, aim directionapply torque or rotate the body

26. Find the frame-rate bug

Error analysis

Three lines, one of which behaves differently on different machines.

Annotate

  • Correct: a continuous force in the physics callback, with no deltaTime - the solver applies the timestep.
  • The bug. Time.deltaTime is the FRAME length, and this is running on the physics clock. Inside FixedUpdate you want Time.fixedDeltaTime. As written, the rotation speed varies with frame rate even though the code is in the right callback.
  • Same bug, quieter: a timer counted down with the wrong clock drifts, and the drift depends on the player's machine.

Inside FixedUpdate, Time.deltaTime actually returns fixedDeltaTime in current Unity versions - but writing it that way still reads as a mistake and breaks the moment the code is moved. Use the clock that matches the callback.

27. Fill in the clock table

Comparison

Complete it from what you have seen.

Comparison matrix

CalledUse which deltaWhat goes here
Updateonce per frameTime.deltaTimeinput, timers, non-physics motion
FixedUpdate50 times a secondTime.fixedDeltaTimeforces, velocity, MovePosition
LateUpdateafter every UpdateTime.deltaTimecamera follow

28. Why fix the physics step at all?

Socratic

Discussion prompt

Unity could simulate physics once per frame with whatever time has passed. Why is a fixed step worth the complexity of a second clock?

Answer:

Because a simulation with a varying step gives different answers on different machines - stacked boxes settle differently, a jump reaches a different height, a replay diverges. Fixed steps make the simulation deterministic given the same inputs.

It also keeps the solver stable: very large steps make springs and stacks explode, and the fixed step puts a ceiling on how large a step can be, no matter how badly the frame rate drops.

29. Moving a body correctly

Section

Part 4

30. Writing transform.position skips the solver

Concept

Figure (svg): Two spheres approaching a thin wall: one teleporting past it in discrete jumps, one stopped at it

Same speed, same wall. The difference is who computed the move.

Setting the position does not move the object through anywhere. It puts it somewhere new. Nothing is swept, nothing is tested, and no contact is generated.

At 15 m/s a 60 fps game moves an object 0.25 units per frame. If the wall is 0.2 thick, then on one frame the object is in front of it and on the next it is behind it - and no collision ever existed.

Unity Scripting API - Rigidbody.MovePosition Rigidbody.MovePosition

31. Predict the race

Prediction

Two spheres, both with Rigidbodies, both at 15 m/s toward the same 0.2-thick wall. Sphere A moves with transform.position +=; sphere B has its velocity set each FixedUpdate.

Predict first

Where does each end up?

  • Both stop at the wall
  • A stops, B passes through
  • A passes through, B stops
  • Both pass through - the wall is too thin

Correct: A passes through with zero collision callbacks; B stops at the wall.

Why: A is not moving fast enough to 'break' physics - it never asked physics anything. B hands the movement to the solver, which sweeps the shape between steps, finds the wall and stops there. Same speed, same wall, same frame rate: the only difference is who computed the move.

32. The two-sphere lab, side by side

Worked example

One script, one enum, two behaviours. This is the whole experiment.

void Update()                                   // style A: teleport
{
    if (style != MoveStyle.TeleportByTransform) return;
    transform.position += Vector3.forward * (speed * Time.deltaTime);
}

void FixedUpdate()                              // style B: ask the solver
{
    if (style == MoveStyle.VelocityByPhysics)
        PhysicsCompat.SetVelocity(body, Vector3.forward * speed);
}
spherehow it movedfinal zcollision callbacks
Atransform.position +=8.50 - past the wall0
Bvelocity, solver moves it3.40 - at the wall1

Both spheres have ContinuousDynamic collision detection

Why: That is deliberate: A still goes through. The setting cannot help a move the solver was never told about.

33. The three correct ways to move

Concept

Which one you use depends on what kind of body it is - and there is exactly one right answer for each.

the object ismove it withwhy
dynamic (physics drives it)AddForce, or set the velocitythe solver integrates it and handles contacts
kinematic (you drive it)MovePosition / MoveRotation in FixedUpdateswept, so riders and contacts behave
no Rigidbody at alltransform.position in Updatethere is no solver to bypass - this is correct here

The third row is worth saying out loud: transform.position is not forbidden. It is the right tool for objects with no Rigidbody, which is most of a UI, most scenery, and every camera.

34. Which mover for which object?

Discrimination

Sort each by the correct way to move it.

Sort into buckets

How should each of these be moved?

Ask the solver (force / velocity / MovePosition)
A player character with a dynamic Rigidbody; A moving platform that carries the player; A bullet that must not pass through walls
Write the transform directly
A floating UI arrow with no Rigidbody
solver
It has a Rigidbody, so the solver owns its position. Dynamic bodies take forces or a velocity; kinematic ones take MovePosition - and both keep collisions working.
direct
No Rigidbody means no solver to bypass, so writing the transform is exactly right. UI, cameras and decorative motion all live here.

35. Trap: 'it has a Rigidbody, so transform moves are safe'

Trap

The trap

The object is a physics object, so surely physics keeps track of wherever I put it.

void Update()
{
    // a dynamic Rigidbody, moved by hand
    transform.position += input * speed * Time.deltaTime;
}
  • Walls are passed through at speed
  • The body's velocity stays whatever it was - so it lurches when you stop
  • Anything resting on it falls through
  • Continuous collision detection does not help, because nothing was swept

The fix

Move it the way its body type expects. For a dynamic body that is a velocity or a force; for a kinematic one, MovePosition.

void FixedUpdate()
{
    // dynamic: hand the intent to the solver
    PhysicsCompat.SetVelocity(body, input * speed);

    // kinematic alternative: swept move, still collision-aware for riders
    // body.MovePosition(body.position + input * speed * Time.fixedDeltaTime);
}
symptomwhat it usually means
passes through walls at speedthe transform is being written
jitters against a walltransform writes fighting the solver each step
riders fall off a platformthe platform teleports instead of sweeping
stops dead, then lurchesvelocity was never part of the movement

36. Push the speed until it breaks

Scale up

Sphere B is moved correctly, with Discrete collision detection. Step the speed up and watch when even the correct method fails.

Step through it

At what point does a correctly-moved body start tunnelling, and what fixes it?

  1. slow: safe
  2. borderline
  3. fast + Discrete: tunnels
  4. fast + Continuous: caught

So there are two separate causes of things going through walls: bypassing the solver (lesson's main point, unfixable by any setting) and sampling too coarsely (fixed by Continuous detection, or a smaller fixed timestep).

37. Build it in Unity

Section

Build

38. What you are about to build

Concept

A physics bench: four spheres printing their own velocity trace, two spheres racing the same wall by different means, and a counter proving the two clocks are different.

ForceLab
One sphere per ForceMode, logging six fixed steps.
TransformVsPhysics
Teleport vs velocity, into a 0.2-thick wall.
ClockCounter
Counts Update against FixedUpdate over two seconds.

Files: unity-labs/Assets/NaruhodoLabs/Lesson03_Physics/.

39. Design the experiment first

Step zero

Discussion prompt

What is the smallest scene that proves writing transform.position skips collision detection? Name what must be true of the wall and of the speed, and why.

Hint: How far does the object move between two checks, compared with how thick the wall is?

Answer:

  • Two spheres, identical apart from how they move - so nothing else can be blamed
  • A thin wall - 0.2 units. A thick wall hides tunnelling, and hiding it is how the belief survives
  • A speed high enough that per-frame distance beats the thickness - 15 m/s at 60 fps is 0.25 per frame
  • A count of collision callbacks - 'it went through' is an observation, '0 callbacks' is proof

That last one is the difference between a demo and an experiment.

40. Step 1: the force bench

Worked example

Four spheres, one per mode, all pushed by 10, all mass 1, gravity off so the Z numbers stay clean.

public class ForceLab : MonoBehaviour
{
    public float pushStrength = 10f;
    public ForceMode mode = ForceMode.Force;

    Rigidbody body;
    void Awake() { body = GetComponent<Rigidbody>(); }

    void FixedUpdate()
    {
        body.AddForce(Vector3.forward * pushStrength, mode);
    }
}

Cache the Rigidbody in Awake, line 7

Why: GetComponent every physics step would be 50 lookups a second per object, for a value that never changes. Lesson 5 measures the cost.

Inspector settingvaluewhy
Mass1makes the arithmetic checkable by hand
Use Gravityoffkeeps the trace to one axis
Push Strength100.20 per step under Force - a round number
Modeone per spherethe whole comparison

41. Commit to the numbers before you press Play

Hypothesis

Mass 2 this time, push 10, six steps, ForceMode.Impulse.

Predict first

What speed will the sphere be doing after step 6?

  • 30 m/s
  • 10 m/s
  • 5 m/s
  • 1.2 m/s

Correct: 5 m/s.

Why: Impulse fires once and is divided by mass: 10 / 2 = 5 m/s, and nothing after step 1 changes it because the push is not repeated. Getting this right means the two questions - spread over time, divided by mass - have become a tool rather than a table you remember.

42. Step 2: the wall race

Worked example

A thin wall and two spheres. Watch the Console, not just the Game view.

// the judgement the lab makes after 1.5 seconds
bool pastWall = transform.position.z > wallZ + 0.3f;
LabLog.Check(L, pastWall && collisionCount == 0,
    "the teleported sphere passed through and fired 0 collision callbacks");
Inspector settingsphere Asphere B
StyleTeleportByTransformVelocityByPhysics
Speed1515
Rigidbodyyes, gravity offyes, gravity off
Collision DetectionContinuousDynamicContinuousDynamic
resultz = 8.5, 0 callbacksz = 3.4, 1 callback

Identical in every row but the first. That is what makes it an experiment rather than a demonstration.

43. Where this shows up in a real game

Real world

Discussion prompt

A player reports that their character sometimes falls through the floor when running down a slope, but only on their machine. You have not been able to reproduce it. What do you check, in order?

Answer:

  1. Is the character moved by writing the transform? If so, that is the whole bug, and it appears on their machine because their frame rate produces bigger per-frame jumps.
  2. Collision detection mode - Discrete on a fast body samples endpoints and can miss thin floors.
  3. Floor thickness - a floor made from a scaled cube 0.05 thick is a tunnelling machine.
  4. Fixed Timestep - if someone raised it to 0.05 for performance, every step is 2.5x longer and every gap 2.5x wider.

Note that all four are the same root cause seen from different angles: the distance travelled between two collision tests got bigger than the thing being tested against.

44. Explain it in three sentences

Explain it

Discussion prompt

Explain to a teammate why their bullet goes through walls, without using the words 'tunnelling' or 'sweep'.

Answer:

Model answer: 'Your bullet is being put in a new place each frame rather than being moved there, so nothing ever checks what was in between.'

'At its speed, one of those jumps starts in front of the wall and ends behind it. Give the bullet a velocity and let physics carry it, and the wall gets found.'

45. Now break it, on purpose

Concept

Six experiments, each under a minute, from the lab's SETUP.md.

changewhat happens
Move AddForce into Update and cap the frame rate to 20the same code produces a different speed
Delete the Rigidbody from a force sphereGetComponent<Rigidbody>() is null and the next line throws
Give the wall a Rigidbodythe wall falls over
Tick Is Kinematic on sphere Bit drives through the wall - kinematic bodies are not stopped by static geometry
Make the wall 2 thick and re-run sphere Ait is stopped - which is how this bug hides in a prototype
Set sphere B to Discrete and speed 60even the correct method tunnels

46. Decode a physics log line

Notation

The lab prints one line per fixed step. Every field on it is worth being able to read at a glance.

Annotate

  • The two numbers every prediction in this lesson depends on. Change either and every figure in the trace changes with it.
  • t = 0.06 is three steps of 0.02 - simulated time, not wall-clock time. The velocity is a Vector3, and only Z is moving because gravity is off.
  • z = -3.958 barely moved: after three steps the sphere is doing 0.6 m/s but has only travelled a few centimetres. Speed accumulates before distance does.
  • A prediction checked against the run. This is the habit worth stealing: state the expected number in the code, so the Console tells you when your model is wrong.

47. Symptom to cause

Matching

Four physics symptoms you will meet. Each has one usual cause.

Match the pairs

Match the symptom to what is almost always behind it.

  • s1. The object hangs in the air
  • s2. The object passes through a wall at speed
  • s3. The object vibrates against a wall
  • s4. The object moves faster on a better PC
  • c1. no Rigidbody
  • c2. the transform is being written instead of the solver being asked
  • c3. your code and the solver are both writing the position
  • c4. a force is being applied in Update

Why: Three of these four are the same root cause wearing different clothes: something other than the solver is deciding where the object is. Being able to go from symptom to cause without opening the code is most of what physics debugging in Unity looks like.

48. Order one physics step

Ranking

Put the events of a single FixedUpdate step in the order Unity performs them.

Put in order

Earliest first.

  1. Your FixedUpdate runs (you call AddForce)
  2. The solver integrates forces into velocity
  3. Bodies are moved and swept along their paths
  4. Contacts are found and resolved
  5. OnCollisionEnter / OnTriggerEnter are delivered

Why: Your code runs FIRST in the step, before anything is simulated - which is why AddForce is a request for what is about to happen rather than a report of what did. The callbacks arrive at the end, so by the time OnCollisionEnter runs the positions have already been resolved and the bodies are no longer overlapping.

49. What would you need to ask?

Missing information

Discussion prompt

A designer says: 'make the crate feel heavier'. Before touching anything, what do you need to know? Name at least three things, and say which Inspector field each would point you at.

Hint: 'Heavier' can mean four different things that need four different fields.

Answer:

  • Harder to get moving? -> mass. A bigger mass means the same Force produces less acceleration.
  • Stops sooner once pushed? -> linearDamping (Drag). Mass alone will not stop it sliding forever.
  • Falls faster? -> nothing. Gravity accelerates everything equally, and this is the request to push back on.
  • Pushes the player around more? -> mass, relative to the player's mass. Only the ratio matters.

The fourth line is the general lesson: physics values are meaningless in isolation. A mass of 500 means nothing until you know what it is standing next to.

50. Two of these are true

Two truths and a lie

One statement is false. Rule it out.

Eliminate the wrong options

Which claim about Rigidbodies is false?

  • A. A kinematic Rigidbody is not stopped by static level geometry.
  • B. Two objects with Colliders but no Rigidbody will still collide with each other.
  • C. Gravity accelerates a heavy body and a light body at the same rate.

Survives elimination: B

Why: Two static colliders never report a collision and never stop each other - the engine does not even test that pair, which is a deliberate performance decision. Lesson 8 turns this into a full matrix, and it is the row that costs people the most time.

51. The procedure: moving anything in Unity

Pattern

Four questions, asked in this order, decide the correct movement code every time.

  1. Does it have a Rigidbody? No - write transform.position in Update, with Time.deltaTime. Done.
  2. Is that Rigidbody kinematic? Yes - MovePosition / MoveRotation in FixedUpdate.
  3. Otherwise it is dynamic - AddForce for a push, or set the velocity for direct control. In FixedUpdate.
  4. Is it fast? Set Collision Detection to Continuous, and check the thing it must not pass through is not razor-thin.

And one rule that spans all four: read input in Update, act in FixedUpdate. A key press that happens between two physics steps is missed if you only look on the physics clock.

52. Check 1: what does a Rigidbody do?

Check

Answer before you click.

Check your understanding

What does adding a Rigidbody to a GameObject actually change?

  • A. It makes the object solid so other objects cannot pass through it
  • B. It hands the object's position and rotation to the physics solver, so gravity, forces and collisions move it (correct)
  • C. It enables collision callbacks, which do not fire without one
  • D. It makes the object heavier, so it interacts more strongly with other objects

Answer: B

Why: A Rigidbody puts the object into the simulation. From then on the solver decides where it is - which is why you ask it to move (forces, velocity, MovePosition) rather than writing the transform yourself.

Why A tempts people
Solidity comes from the Collider. A wall with no Rigidbody stops things perfectly well - that is what most level geometry is.
Why C tempts people
Close, and this is the tempting one: a collision needs a Rigidbody somewhere in the PAIR, but the object receiving the callback does not need one itself. Lesson 8 has the full matrix.
Why D tempts people
Mass is a field on the Rigidbody, not the reason for adding one, and a heavier object is harder to push, not more interactive.

53. Check 2: where does the force go?

Check

The callback question the diagnostic left blank.

Check your understanding

Why should AddForce be called from FixedUpdate rather than Update?

  • A. Update cannot access the Rigidbody component
  • B. FixedUpdate runs a fixed number of times per second, so the same code produces the same motion on every machine (correct)
  • C. Forces applied in Update are ignored by the physics engine
  • D. FixedUpdate runs faster, so the object accelerates more smoothly

Answer: B

Why: The physics clock is fixed at 50 steps a second regardless of frame rate. A force applied in Update lands once per frame, which is a different number of times on every machine, so the resulting speed depends on the player's hardware.

Why A tempts people
Update can reach any component. Nothing is inaccessible - the problem is timing, not access.
Why C tempts people
They are not ignored; they are applied at the next physics step. That is exactly why the bug is so hard to spot - it works, just inconsistently.
Why D tempts people
FixedUpdate is usually SLOWER than Update on a modern machine (50 vs 144). The point is regularity, not speed.

54. One movement bug, four suspects

Elimination

A crate with a dynamic Rigidbody jitters violently when the player pushes it against a wall.

Eliminate the wrong options

Which is the most likely cause?

  • A. A script writes the crate's transform.position every frame while the solver also resolves the wall contact.
  • B. The crate's mass is too low.
  • C. The wall has no Rigidbody.
  • D. Collision detection is set to Discrete.

Survives elimination: A

Why: Jitter is the signature of two authorities writing the same position: your code puts the crate inside the wall, the solver pushes it out, and next frame your code puts it back. Passing through is the signature of bypassing the solver at speed; jittering is the signature of fighting it at close range.

55. Check 3: the sphere and the wall

Check

The last one.

Check your understanding

A sphere with a Rigidbody is moved by transform.position += forward * 15f * Time.deltaTime in Update. It passes through a thin wall. What is the fix?

  • A. Set Collision Detection to Continuous
  • B. Increase the wall's thickness
  • C. Move it with the physics system instead - set the velocity or use AddForce in FixedUpdate (correct)
  • D. Move the same line into FixedUpdate

Answer: C

Why: Writing the position bypasses collision detection entirely: the object is placed at a new location and nothing checks the path. Handing the movement to the solver is what makes the wall exist as far as this object is concerned.

Why A tempts people
Continuous detection sweeps moves the SOLVER makes. It cannot sweep a move it was never told about, which the lab demonstrates by turning it on for both spheres.
Why B tempts people
It hides the bug at this speed and it comes back at a higher one. Fixing a symptom by making the test easier is how this survives to a build.
Why D tempts people
The same write, on a different clock, is still a write. The object still teleports; it now teleports 50 times a second instead of 60.

56. A feel for the numbers

Estimation

A bullet travels at 100 m/s. The fixed timestep is 0.02s.

Predict first

How far does it move between two physics steps?

  • 0.02 m
  • 0.2 m
  • 2 m
  • 20 m

Correct: 2 metres.

Why: 100 x 0.02 = 2 metres per step. Any wall thinner than 2 metres can be skipped by a discrete check, which is why fast projectiles are usually done with a raycast along the path rather than by moving a collider at all - and why 'my bullets go through walls' is the single most common physics question a beginner asks.

57. What this unlocks

Concept

Lesson 8 is the other half of this one: you now know what makes an object physical, and lesson 8 is about which pairs of physical objects actually report contact.

you now havewhat it enables
Rigidbody as 'the solver owns it'predicting whether something will move
the four ForceModesjumps, thrust, hits and recoil that feel right
the two clocksmovement that behaves the same on every machine
the tunnelling modeldiagnosing pass-through bugs from a description

58. Connect it to something you know

Analogy

The two-clock split exists outside games too.

Match the pairs

Match each Unity idea to its cousin elsewhere.

  • u1. FixedUpdate
  • u2. Update
  • u3. Writing transform.position on a physics body
  • u4. Continuous collision detection
  • o1. a simulation tick in a scientific model
  • o2. a UI redraw at whatever rate the screen manages
  • o3. editing a database file behind the running database
  • o4. checking the whole path, not just the endpoints

Why: The third pairing is the one to keep: writing the transform behind the solver is exactly editing the file under a running database, and the failure mode is the same - it appears to work, and the corruption shows up later somewhere unrelated.

59. Draw the decision

Connect it up

Draw it

Draw the movement decision as a flow chart: 'Does it have a Rigidbody?' at the top, branching to no / kinematic / dynamic, with the correct call written at the end of each branch and which callback it belongs in.

60. Before you close this

Exit ticket

Predict first

Which is still shakiest?

  • What a Rigidbody changes
  • The four ForceModes
  • Update vs FixedUpdate
  • Why transform moves pass through walls

Correct: Whichever you picked - open the lab scene and run the experiment for that one.

Why: This was 0 out of 3 in the diagnostic, so every one of these is new rather than shaky, and expecting to have all four solid after one pass is unrealistic. Pick the weakest, run its experiment in the lab, and bring the numbers you got to the next session.

61. What you can now do

Recap

You can predict whether an object will move, how fast, and whether it will notice a wall.

Lab: unity-labs/Assets/NaruhodoLabs/Lesson03_Physics/SETUP.md. Reproduce the force trace by hand before you move on.

Sources

  1. Unity Manual - Rigidbody component reference
  2. Unity Scripting API - Rigidbody.AddForce
  3. Unity Scripting API - ForceMode
  4. Unity Manual - Order of execution for event functions
  5. Unity Scripting API - Rigidbody.MovePosition
  6. Naruhodo Unity Labs - Lesson 03 setup notes — unity-labs/Assets/NaruhodoLabs/Lesson03_Physics/SETUP.md

Want this taught 1-on-1? Alexander tutors Unity Game Engine — $55/session, free consultation.

Book on Wyzant · Text (657) 465-8108