Game Development with Godot & GDScript Module 6
Game math and 2D physics interview questions
Interview questions on game math and 2D physics: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
What does the dot product of a guard's facing and the direction to the player tell you?
-
Fresher
What is the difference between position and global_position on a Node2D?
-
Fresher
What is the difference between a collision layer and a collision mask?
-
Fresher
Why is velocity not multiplied by delta before move_and_slide()?
Answered in the lesson Platformer and top-down character controllers
-
Fresher
What is the difference between an impulse and a force on a RigidBody2D?
Answered in the lesson Rigid bodies, raycasts and physics queries
-
Fresher
What is the difference between _process() and _physics_process()?
Answered in the lesson Physics ticks, interpolation and jitter
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Fresher to mid
Playtesters say stealth guards notice them from far off to the side, almost behind, although guards should see only 90 degrees ahead. The check is facing.dot(player.global_position - global_position) > 0.707. What is wrong, how do you fix it, and how do you keep the check cheap for 200 guards?
- What it tests
- Knowing that the dot product is the cosine only for unit vectors, comparing with the cosine of the half-angle, and keeping a per-tick check cheap with squared distances and early exits.
- First step
- Write the dot product out: it is the offset's length times the facing's length times the cosine of the angle. With a raw offset the left side grows with the distance, so a player 180 px away and 56 degrees off gives 100, far above 0.707. Normalize the offset, or use direction_to(), before comparing with cos(45°).
- Follow-ups
-
- Why compare with cos(45°), and not with 0 or with cos(90°)?
- How do you add line of sight, so that walls block the view?
- How do you avoid a square root and a normalize for 200 guards on every tick?
From the lesson Vector math for games
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Fresher to mid
A camera follows the player with position = position.lerp(target, 0.1) in _process(). On 144 Hz monitors players call it twitchy, and on a slow laptop it lags behind. Explain why, fix it so that it feels the same everywhere, and say how you would test the fix.
- What it tests
- Seeing that a fixed lerp weight per frame compounds with the frame rate, deriving a frame-rate independent weight from exp(-k * delta), and testing motion at fixed frame rates.
- First step
- Count the frames. Each one takes 0.1 of the remaining gap, so 144 frames a second take far more shares in the same time than 30: in half a second the camera closes 99.95 % of a jump at 144 and 79.41 % at 30. The share must depend on how long the frame lasted.
- Follow-ups
-
- How do you choose k so that the camera keeps the feel it had at 60 frames a second?
- Would moving the camera in _physics_process() fix it?
- How do you test the fix without a 144 Hz monitor?
From the lesson Vector math for games
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Fresher to mid
A turret mounted on a ship aims perfectly while the ship faces right and misses more the more the ship turns. It sets rotation = (target.global_position - global_position).angle(). Explain the miss with numbers, give two fixes, and say how the fix changes when the turret sits on a mount that also turns.
- What it tests
- Knowing that rotation is relative to the parent, converting with to_local() or look_at(), and composing several parents' transforms.
- First step
- Name the spaces. The angle is measured in the world, but rotation is relative to the ship, so the ship's own turn is added on top: a ship turned 30 degrees makes the muzzle point 30 degrees off. The angle has to be measured in the parent's space, or the parent's rotation taken off.
- Follow-ups
-
- Which fix still works when the ship is scaled?
- How does the fix change for a turret on a mount on the ship?
- The turret should turn towards the target at a capped rate. What changes?
From the lesson Transforms and coordinate spaces
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Markers on the HUD that should sit over enemies are placed at each enemy's global_position. They look right in the first room, drift away as the camera follows the player, and jump when the player turns on a UI scale of 200 %. Explain each symptom and design the conversion.
- What it tests
- Following a point through the canvas transform of a Camera2D and a CanvasLayer's own transform, and keeping world-sized and screen-sized things in the right space.
- First step
- List the transforms between the enemy and the HUD. The enemy's global position is in the world; the camera's canvas transform takes it to the screen; the HUD layer's transform, with its scale, takes HUD points to the screen. The marker needs the screen point taken back through the layer.
- Follow-ups
-
- Why does it look right in the first room?
- How do you show a marker for an enemy that is off the screen?
- When should a health bar be a child of the enemy instead?
From the lesson Transforms and coordinate spaces
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Design the collision layers and masks of a co-op shooter: two players, enemies, player shots, enemy shots, pickups and walls, with friendly fire off. Say which node each object is, what each mask holds, and how you would test that exactly the right pairs interact.
- What it tests
- Turning an interaction table into layers and masks, knowing that detection runs from the mask's side, choosing bodies and areas, and testing the whole table automatically.
- First step
- Write the table from the detector's side: one row per kind, listing what it must detect. Give each kind its own layer, then each mask is the sum of the bits in its row. Shots are areas, so they only report; players and enemies are character bodies that look at walls.
- Follow-ups
-
- Why not one layer for all shots?
- How would you turn friendly fire on as a game option?
- How do you stop the defaults from sneaking back in?
From the lesson Physics bodies, layers and masks
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A moving platform is a StaticBody2D that an AnimationPlayer moves up and down. Crates on it rise with it but never fly off when it stops sharply, and players report that jumps from it feel wrong. Explain what happens and what you would change.
- What it tests
- Knowing that a moved StaticBody2D teleports without giving bodies its speed, that an AnimatableBody2D pushes with its own velocity, and how a character inherits a platform's speed.
- First step
- Measure the crate's speed while it rides. A StaticBody2D moved by code is teleported; the crate is pushed out of it each tick but keeps a speed of 0, so it has nothing to fly off with. An AnimatableBody2D moves through the physics step and gives what it pushes its own speed.
- Follow-ups
-
- What does sync_to_physics do, and when must it be off?
- How does a CharacterBody2D keep the platform's speed when it jumps off?
- Could the platform be a RigidBody2D instead?
From the lesson Physics bodies, layers and masks
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A designer specifies a jump: 96 px high, 0.4 s to the top, forgiving of presses a little late or early, and lower when the button is let go early. Write down the controller's numbers and logic, explain why a naive version jumps 100 px, and say how you would prove the spec holds.
- What it tests
- Deriving gravity and jump speed from height and time, the error of stepping a jump tick by tick, coyote time and buffers in seconds, and headless tests that replay input on exact ticks.
- First step
- From constant acceleration: g = 2h / t² = 1,200 px/s² and v = 2h / t = 480 px a second. Then check the stepping: moving with the speed at the end of each tick runs ahead of the curve, and the first tick at the full speed adds a whole 8 px.
- Follow-ups
-
- How does the controller stay right if the project changes to 120 ticks a second?
- How do coyote time and the buffer interact on the same tick?
- What exactly would your automated test measure?
From the lesson Platformer and top-down character controllers
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Fresher to mid
On a level with long downhill slopes, the hero visibly bounces as it runs down, its jumps are sometimes ignored on the way down, and it runs faster downhill than on the flat. Uphill, a 50-degree ramp stops it dead. Explain each symptom and the settings you would change.
- What it tests
- Knowing floor_snap_length, floor_max_angle and floor_constant_speed, and how leaving the ground for a tick breaks is_on_floor() and with it jumping.
- First step
- Count the ticks the hero spends in the air on the slope. Each move along the velocity ends above the falling ground, gravity brings it back a tick later, and on every airborne tick is_on_floor() is false, so a jump pressed then is refused. Snapping keeps it on the ground.
- Follow-ups
-
- How long should the snap be?
- Should the hero run faster downhill?
- How do you let the hero climb the 50-degree ramp, and should you?
From the lesson Platformer and top-down character controllers
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Enemies in a stealth game sometimes see the player through walls, and sometimes fail to see a player standing in the open in front of them, half hidden by a crate. Each enemy casts one ray to the player's centre with the default query parameters. Diagnose both bugs and design a better sight check.
- What it tests
- Masks and exclusions in ray queries, reading an empty result versus a hit, rays from a point versus the body's size, and the order and cost of the checks.
- First step
- Look at what the default ray can hit: every layer, so the player's own body or a crate counts as a blocker. Then look at where it starts: an enemy pressed against a wall has its eye inside the wall's shape, and a ray that starts inside a shape skips it. Give the ray only the blockers' layers, and start it outside walls.
- Follow-ups
-
- Why can one ray to the centre miss a half-hidden player?
- How do you keep 50 enemies' checks cheap?
- Where in the frame do the queries run, and why?
From the lesson Rigid bodies, raycasts and physics queries
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A physics puzzle game stores replays as the player's inputs and re-simulates them. Replays look right on the developer's machine, but players report that boxes end up elsewhere, especially after a patch that raised the physics tick rate. Explain what is happening and design replays and tests that hold up.
- What it tests
- What a physics simulation's result depends on (build, tick rate, order of events, platform), and recording results or pinning every input of the simulation instead.
- First step
- List what the result depends on besides the inputs: the tick rate, the build and engine version, the order in which bodies were added and the machine's floating-point behaviour. Raising the tick rate alone changes every result, so every old replay re-simulated under the new rate has diverged.
- Follow-ups
-
- What exactly would you record instead?
- How would you test the physics without brittle numbers?
- When is input-only replay still acceptable?
From the lesson Rigid bodies, raycasts and physics queries
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A 2D platformer looks smooth on 60 Hz monitors, but players with 144 Hz monitors say the hero and the scrolling level shake. Physics runs at 60 ticks a second and interpolation is off. Explain the shake with numbers, fix it, and say what else in the code the fix makes you change.
- What it tests
- Ticks against frames, physics interpolation and its rules (movement in ticks, resets after teleports, cameras), and the cost in input delay.
- First step
- Count ticks per frame. At 144 frames and 60 ticks a second, two or three frames share each tick, so a hero at 300 units a second is drawn moving 0, 0 and then 5 units, an uneven step on a 60 Hz rhythm. On 60 Hz screens every frame has one tick, which is why it looks fine there.
- Follow-ups
-
- What must change in the code once interpolation is on?
- How should the camera follow the hero?
- What does the fix cost, and how would you reduce that?
From the lesson Physics ticks, interpolation and jitter
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A game's physics tests run headless on a build server. They take several minutes, and a few fail now and then with positions a little off, then pass on a rerun. Explain both problems and design a test setup that is fast and gives the same answer every time.
- What it tests
- Real-time synchronization against --fixed-fps, what makes a physics run repeat (frame time, jitter fix, tick rate, input timing, scene order), and tolerances.
- First step
- Without options, a headless run keeps physics in step with the wall clock, so 120 ticks wait two seconds whatever the machine. --fixed-fps gives every frame a fixed game time and drops that wait. The random failures point to anything still taken from the clock or the frame timing.
- Follow-ups
-
- Why do positions differ between reruns at all?
- How do tests press inputs on an exact tick?
- What tolerance would you use, and why not exact equality?
From the lesson Physics ticks, interpolation and jitter
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
All Game Development with Godot & GDScript interview questions · The Game Development with Godot & GDScript track