
Physics puzzle
You solve each level by exploiting consistent physics: throwing, stacking, balancing or building contraptions so that gravity, momentum and collisions do the work. The challenge is predicting how objects will react.
Also known as: physics game, physics-based puzzle
This is a basic entry: it has the definition and the classification. Full entries add history, games and a demo.
Our demo
Controls. Left and right arrows (or A and D) to turn the launcher, up and down (or W and S) to raise or lower the angle. Hold space to charge the power and release to fire. R restarts the level. On mobile, the on-screen buttons.
Open full screenThree 3D levels in which you launch a heavy ball at block structures to knock some red targets off a platform, with only three shots per level. Nothing is scripted in advance: the blocks fall, roll and push each other according to physics, so the challenge is predicting how the structure will react. It is made with threeplay, which simulates collisions with Rapier.
Made with threeplay, in about 180 lines of JavaScript.
How it's made
Setup and controls
The game is created at 640×360 with virtual buttons to aim, fire and restart; the on-screen mobile buttons press those same buttons. Gravity (setGravity) and the constants for the platform and the number of shots set the rules of the puzzle.
const k = threeplay({ width: 640, height: 360, letterbox: true, background: "#a8dadc", buttons: { left: { keyboard: ["left", "a"] }, right: { keyboard: ["right", "d"] }, up: { keyboard: ["up", "w"] }, down: { keyboard: ["down", "s"] }, fire: { keyboard: ["space"] }, restart: { keyboard: ["r"] }, }, }); touchControls(k, [ { button: "left", label: "◀" }, { button: "up", label: "▲" }, { button: "down", label: "▼" }, { button: "right", label: "▶" }, { button: "restart", label: "↺", side: "right" }, { button: "fire", label: "●", side: "right" }, ]); setGravity(15); const LAUNCHER = vec3(0, 0.9, 0); const PLATFORM_Z = -14; // the structures stand on a platform this far away const PLATFORM_TOP = 2; const SHOTS = 3;Levels made of data
Each level is a list of blocks (position and size) and targets. buildLevel() gives them body(), which makes them dynamic bodies: they have mass, fall and spin when hit. Mass comes from each block's volume, so a thin pillar topples easily and a thick wall holds. Designing a level means choosing where the structure's weak point is.
// Blocks are [x, y, z, width, height, depth] relative to the platform top; // targets are [x, y, z]. Nothing here is scripted: the physics decides. const LEVELS = [ { blocks: [[-0.8, 0.75, 0, 0.4, 1.5, 0.4], [0.8, 0.75, 0, 0.4, 1.5, 0.4], [0, 1.65, 0, 2.2, 0.3, 0.6]], targets: [[0, 2.2, 0]], }, { blocks: [ [-1, 0.5, -1.2, 1, 1, 0.5], [0, 0.5, -1.2, 1, 1, 0.5], [1, 0.5, -1.2, 1, 1, 0.5], [-0.6, 0.6, -2.2, 0.4, 1.2, 0.4], [0.6, 0.6, -2.2, 0.4, 1.2, 0.4], ], targets: [[-0.6, 1.6, -2.2], [0.6, 1.6, -2.2]], }, { blocks: [ [-2.2, 0.75, 0, 0.6, 1.5, 0.6], [-2.2, 2.25, 0, 0.6, 1.5, 0.6], [2.2, 0.75, 0, 0.6, 1.5, 0.6], [2.2, 2.25, 0, 0.6, 1.5, 0.6], ], targets: [[-2.2, 3.4, 0], [2.2, 3.4, 0]], }, ]; function buildLevel(n) { add([box(60, 1, 60), pos(0, -0.5, -10), color("#8ab17d"), area({ friction: 0.8 }), body({ isStatic: true })]); add([box(8, PLATFORM_TOP, 6), pos(0, PLATFORM_TOP / 2, PLATFORM_Z), color("#6c757d"), area(), body({ isStatic: true })]); for (const [x, y, z, w, h, d] of LEVELS[n].blocks) { add([box(w, h, d), pos(x, PLATFORM_TOP + y, PLATFORM_Z + z), rotate(), color("#e9c46a"), area({ friction: 0.7 }), body({ mass: w * h * d * 4 }), "block"]); } for (const [x, y, z] of LEVELS[n].targets) { add([sphere(0.4), pos(x, PLATFORM_TOP + y, PLATFORM_Z + z), rotate(), color("#e63946"), area(), body({ mass: 0.5 }), "target"]); } }The launcher and the guide
The launcher stores the heading, the angle and the power, and launchVelocity() turns them into a starting velocity. The ball is heavy and uses ccd (continuous collision detection) so it does not pass through blocks at high speed. The white dots draw only the start of the parabola, computed with the same gravity: they help you aim, but you have to predict the end of the flight yourself.
// Aim with yaw (left/right) and pitch (up/down); hold to charge, release to fire. function launchVelocity(aim) { const speed = 9 + aim.power * 15; const yaw = (aim.yaw * Math.PI) / 180; const pitch = (aim.pitch * Math.PI) / 180; return vec3(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), -Math.cos(yaw) * Math.cos(pitch)).multiplyScalar(speed); } function fireBall(aim) { const ball = add([sphere(0.35), pos(LAUNCHER.clone()), rotate(), color("#1d3557"), area({ restitution: 0.2 }), body({ mass: 8, ccd: true }), "ball"]); ball.vel = launchVelocity(aim); beep({ freq: 180, slideTo: 90, duration: 0.25, type: "square" }); wait(8, () => destroy(ball)); return ball; } // The guide only shows the start of the arc: predicting the rest is the puzzle. function guideDots() { return Array.from({ length: 12 }, () => add([sphere(0.07), pos(0, -5, 0), color("#ffffff")])); } function updateGuide(dots, aim) { const v = launchVelocity(aim); const g = getGravity(); dots.forEach((dot, i) => { const s = (i + 1) * 0.05; dot.pos = LAUNCHER.clone().addScaledVector(v, s).addScaledVector(g, 0.5 * s * s); }); }The counter
The counter shows the level, the shots left and the targets still standing, and a bar shows how much power you have charged. Those are the three facts you use to decide the next shot.
const info = add([text("", { size: 16, font: FONT }), pos(14, 10), fixed()]); add([uiRect(124, 14, { radius: 3, outline: "#1d3557" }), pos(14, 40), color("#ffffff"), opacity(0.5), fixed()]); const bar = add([uiRect(1, 10, { radius: 2 }), pos(16, 42), color("#e76f51"), fixed()]); add([ text(t({ es: "Mantén espacio para cargar · R reinicia", en: "Hold space to charge · R restarts" }), { size: 12, font: FONT }), pos(626, 10), anchor("topright"), fixed(), ]); function updateHud() { const left = get("target").filter((tg) => !fallen(tg)).length; info.text = t({ es: `Nivel ${level + 1}/${LEVELS.length} · Tiros: ${shots} · Objetivos: ${left}`, en: `Level ${level + 1}/${LEVELS.length} · Shots: ${shots} · Targets: ${left}`, }); bar.width = Math.max(1, aim.power * 120); }Winning with physics
A target counts once it drops below the platform, not when you touch it: what matters is the physical result. After each shot the game waits a few seconds for the pile to stop moving before judging, because a tower may take a while to fall. If you run out of shots with targets still standing, the level restarts.
// A target counts once it drops below the platform: knocked off, not just touched. function fallen(target) { return target.pos.y < PLATFORM_TOP - 0.3; } function checkResult() { if (get("target").every(fallen)) return go("cleared", level); if (shots === 0) go("failed", level); }Scenes
Title, game, level cleared and out of shots (title, game, cleared and failed). The title screen reuses the first level with a camera that orbits on its own, and the failure screen suggests looking at where each shot hit, which is how you learn in this genre.
function screen(title, subtitle, prompt) { add([uiRect(520, 160, { radius: 8 }), pos(320, 180), anchor("center"), color("#1d3557"), opacity(0.6), fixed()]); add([text(title, { size: 34, font: FONT }), pos(320, 130), anchor("center"), fixed()]); add([text(subtitle, { size: 15, font: FONT }), pos(320, 180), anchor("center"), fixed()]); add([text(prompt, { size: 16, font: FONT }), pos(320, 230), anchor("center"), fixed()]); } scene("title", () => { buildLevel(0); orbitCamera({ target: vec3(0, 2, PLATFORM_Z), distance: 14, autoRotate: 12, interactive: false }); screen( t({ es: "Derribar", en: "Topple" }), t({ es: "Tira los objetivos rojos de la plataforma con pocos tiros", en: "Knock the red targets off the platform with few shots" }), t({ es: "Espacio para empezar", en: "Space to start" }), ); onButtonPress("fire", () => go("game", 0)); }); scene("cleared", (level) => { const last = level === LEVELS.length - 1; beep({ freq: 523, slideTo: 1046, duration: 0.5, type: "triangle" }); screen( last ? t({ es: "¡Todo derribado!", en: "Everything toppled!" }) : t({ es: "¡Nivel superado!", en: "Level cleared!" }), last ? t({ es: "Superaste los tres niveles.", en: "You cleared all three levels." }) : t({ es: `Siguiente: nivel ${level + 2}`, en: `Next: level ${level + 2}` }), t({ es: "Espacio para seguir", en: "Space to continue" }), ); onButtonPress("fire", () => go(last ? "title" : "game", last ? undefined : level + 1)); }); scene("failed", (level) => { screen( t({ es: "Sin tiros", en: "Out of shots" }), t({ es: "Mira dónde golpeó cada tiro y prueba otro ángulo.", en: "Look at where each shot hit and try another angle." }), t({ es: "Espacio para reintentar", en: "Space to retry" }), ); onButtonPress("fire", () => go("game", level)); }); go("title");
What we simplified
- There is only one kind of projectile and one block material. Games in the genre usually mix materials (wood, stone, ice) that resist differently, and projectiles with special abilities.
- Blocks do not break; they only fall. There is also no star rating or score for shots left over.
- The camera is fixed and the sound is synthesized beeps.
To modify it
- Design a fourth level in LEVELS with a structure that only falls if you hit its weak point, and check that it can be won with three shots.
- Add a second block material, heavier and in another colour, and see how it changes the way the levels are solved.
- Make the guide show the whole trajectory and play again. Does the puzzle get easier, or does it lose its appeal?
Full code
import threeplay from "../../vendor/threeplay/threeplay.mjs";
import { FONT, t, touchControls } from "../common.js";
// #region setup
const k = threeplay({
width: 640,
height: 360,
letterbox: true,
background: "#a8dadc",
buttons: {
left: { keyboard: ["left", "a"] },
right: { keyboard: ["right", "d"] },
up: { keyboard: ["up", "w"] },
down: { keyboard: ["down", "s"] },
fire: { keyboard: ["space"] },
restart: { keyboard: ["r"] },
},
});
touchControls(k, [
{ button: "left", label: "◀" },
{ button: "up", label: "▲" },
{ button: "down", label: "▼" },
{ button: "right", label: "▶" },
{ button: "restart", label: "↺", side: "right" },
{ button: "fire", label: "●", side: "right" },
]);
setGravity(15);
const LAUNCHER = vec3(0, 0.9, 0);
const PLATFORM_Z = -14; // the structures stand on a platform this far away
const PLATFORM_TOP = 2;
const SHOTS = 3;
// #endregion
// #region levels
// Blocks are [x, y, z, width, height, depth] relative to the platform top;
// targets are [x, y, z]. Nothing here is scripted: the physics decides.
const LEVELS = [
{
blocks: [[-0.8, 0.75, 0, 0.4, 1.5, 0.4], [0.8, 0.75, 0, 0.4, 1.5, 0.4], [0, 1.65, 0, 2.2, 0.3, 0.6]],
targets: [[0, 2.2, 0]],
},
{
blocks: [
[-1, 0.5, -1.2, 1, 1, 0.5], [0, 0.5, -1.2, 1, 1, 0.5], [1, 0.5, -1.2, 1, 1, 0.5],
[-0.6, 0.6, -2.2, 0.4, 1.2, 0.4], [0.6, 0.6, -2.2, 0.4, 1.2, 0.4],
],
targets: [[-0.6, 1.6, -2.2], [0.6, 1.6, -2.2]],
},
{
blocks: [
[-2.2, 0.75, 0, 0.6, 1.5, 0.6], [-2.2, 2.25, 0, 0.6, 1.5, 0.6],
[2.2, 0.75, 0, 0.6, 1.5, 0.6], [2.2, 2.25, 0, 0.6, 1.5, 0.6],
],
targets: [[-2.2, 3.4, 0], [2.2, 3.4, 0]],
},
];
function buildLevel(n) {
add([box(60, 1, 60), pos(0, -0.5, -10), color("#8ab17d"), area({ friction: 0.8 }), body({ isStatic: true })]);
add([box(8, PLATFORM_TOP, 6), pos(0, PLATFORM_TOP / 2, PLATFORM_Z), color("#6c757d"), area(), body({ isStatic: true })]);
for (const [x, y, z, w, h, d] of LEVELS[n].blocks) {
add([box(w, h, d), pos(x, PLATFORM_TOP + y, PLATFORM_Z + z), rotate(), color("#e9c46a"), area({ friction: 0.7 }), body({ mass: w * h * d * 4 }), "block"]);
}
for (const [x, y, z] of LEVELS[n].targets) {
add([sphere(0.4), pos(x, PLATFORM_TOP + y, PLATFORM_Z + z), rotate(), color("#e63946"), area(), body({ mass: 0.5 }), "target"]);
}
}
// #endregion
// #region launcher
// Aim with yaw (left/right) and pitch (up/down); hold to charge, release to fire.
function launchVelocity(aim) {
const speed = 9 + aim.power * 15;
const yaw = (aim.yaw * Math.PI) / 180;
const pitch = (aim.pitch * Math.PI) / 180;
return vec3(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), -Math.cos(yaw) * Math.cos(pitch)).multiplyScalar(speed);
}
function fireBall(aim) {
const ball = add([sphere(0.35), pos(LAUNCHER.clone()), rotate(), color("#1d3557"), area({ restitution: 0.2 }), body({ mass: 8, ccd: true }), "ball"]);
ball.vel = launchVelocity(aim);
beep({ freq: 180, slideTo: 90, duration: 0.25, type: "square" });
wait(8, () => destroy(ball));
return ball;
}
// The guide only shows the start of the arc: predicting the rest is the puzzle.
function guideDots() {
return Array.from({ length: 12 }, () => add([sphere(0.07), pos(0, -5, 0), color("#ffffff")]));
}
function updateGuide(dots, aim) {
const v = launchVelocity(aim);
const g = getGravity();
dots.forEach((dot, i) => {
const s = (i + 1) * 0.05;
dot.pos = LAUNCHER.clone().addScaledVector(v, s).addScaledVector(g, 0.5 * s * s);
});
}
// #endregion
scene("game", (level = 0) => {
buildLevel(level);
camPos(0, 4.5, 7.5);
camLookAt(vec3(0, 2, PLATFORM_Z));
// The launcher keeps the aim: yaw and pitch in degrees, power from 0 to 1.
const aim = add([cylinder(0.35, 0.7), pos(0, 0.35, 0), color("#264653"), "launcher", { yaw: 0, pitch: 20, power: 0, charging: false }]);
let shots = SHOTS;
let settling = null; // timer that waits for the pile to stop moving
const dots = guideDots();
// #region hud
const info = add([text("", { size: 16, font: FONT }), pos(14, 10), fixed()]);
add([uiRect(124, 14, { radius: 3, outline: "#1d3557" }), pos(14, 40), color("#ffffff"), opacity(0.5), fixed()]);
const bar = add([uiRect(1, 10, { radius: 2 }), pos(16, 42), color("#e76f51"), fixed()]);
add([
text(t({ es: "Mantén espacio para cargar · R reinicia", en: "Hold space to charge · R restarts" }), { size: 12, font: FONT }),
pos(626, 10),
anchor("topright"),
fixed(),
]);
function updateHud() {
const left = get("target").filter((tg) => !fallen(tg)).length;
info.text = t({
es: `Nivel ${level + 1}/${LEVELS.length} · Tiros: ${shots} · Objetivos: ${left}`,
en: `Level ${level + 1}/${LEVELS.length} · Shots: ${shots} · Targets: ${left}`,
});
bar.width = Math.max(1, aim.power * 120);
}
// #endregion
// #region physics-rules
// A target counts once it drops below the platform: knocked off, not just touched.
function fallen(target) {
return target.pos.y < PLATFORM_TOP - 0.3;
}
function checkResult() {
if (get("target").every(fallen)) return go("cleared", level);
if (shots === 0) go("failed", level);
}
// #endregion
onUpdate(() => {
const turn = (isButtonDown("right") ? 1 : 0) - (isButtonDown("left") ? 1 : 0);
const tilt = (isButtonDown("up") ? 1 : 0) - (isButtonDown("down") ? 1 : 0);
aim.yaw = Math.max(-35, Math.min(35, aim.yaw + turn * 30 * dt()));
aim.pitch = Math.max(0, Math.min(70, aim.pitch + tilt * 30 * dt()));
if (aim.charging) aim.power = Math.min(1, aim.power + dt() / 1.2);
updateGuide(dots, aim);
updateHud();
if (get("target").every(fallen) && !settling) settling = wait(1, checkResult);
});
onButtonPress("fire", () => {
if (shots > 0) aim.charging = true;
});
onButtonRelease("fire", () => {
if (!aim.charging) return;
aim.charging = false;
fireBall(aim);
shots--;
aim.power = 0;
// Wait for the blocks to settle before judging the last shot fired.
settling?.cancel();
settling = wait(4, () => {
settling = null;
checkResult();
});
});
onButtonPress("restart", () => go("game", level));
onCollide("ball", "block", () => beep({ freq: 120, duration: 0.05, type: "triangle" }));
});
// #region scenes
function screen(title, subtitle, prompt) {
add([uiRect(520, 160, { radius: 8 }), pos(320, 180), anchor("center"), color("#1d3557"), opacity(0.6), fixed()]);
add([text(title, { size: 34, font: FONT }), pos(320, 130), anchor("center"), fixed()]);
add([text(subtitle, { size: 15, font: FONT }), pos(320, 180), anchor("center"), fixed()]);
add([text(prompt, { size: 16, font: FONT }), pos(320, 230), anchor("center"), fixed()]);
}
scene("title", () => {
buildLevel(0);
orbitCamera({ target: vec3(0, 2, PLATFORM_Z), distance: 14, autoRotate: 12, interactive: false });
screen(
t({ es: "Derribar", en: "Topple" }),
t({ es: "Tira los objetivos rojos de la plataforma con pocos tiros", en: "Knock the red targets off the platform with few shots" }),
t({ es: "Espacio para empezar", en: "Space to start" }),
);
onButtonPress("fire", () => go("game", 0));
});
scene("cleared", (level) => {
const last = level === LEVELS.length - 1;
beep({ freq: 523, slideTo: 1046, duration: 0.5, type: "triangle" });
screen(
last ? t({ es: "¡Todo derribado!", en: "Everything toppled!" }) : t({ es: "¡Nivel superado!", en: "Level cleared!" }),
last
? t({ es: "Superaste los tres niveles.", en: "You cleared all three levels." })
: t({ es: `Siguiente: nivel ${level + 2}`, en: `Next: level ${level + 2}` }),
t({ es: "Espacio para seguir", en: "Space to continue" }),
);
onButtonPress("fire", () => go(last ? "title" : "game", last ? undefined : level + 1));
});
scene("failed", (level) => {
screen(
t({ es: "Sin tiros", en: "Out of shots" }),
t({ es: "Mira dónde golpeó cada tiro y prueba otro ángulo.", en: "Look at where each shot hit and try another angle." }),
t({ es: "Espacio para reintentar", en: "Space to retry" }),
);
onButtonPress("fire", () => go("game", level));
});
go("title");
// #endregionHistory
- 1993Origin
There is no recognised first game. The Incredible Machine (1993), in which you build Rube Goldberg machines, is the oldest of the examples Wikipedia cites.
Puzzle video game (Wikipedia) - 2008
The independent World of Goo builds structures out of goo balls that bend and topple.
World of Goo (Wikipedia) - 2009
Angry Birds brings the physics puzzle to touchscreen phones with its slingshot.
Angry Birds (video game) (Wikipedia)
Reference games
2009
Angry Birds
You fling birds with a slingshot at structures of wood, stone and ice to knock down the pigs hiding in them. The physics of the collisions decides what falls and what holds.
2010
Cut the Rope
A sweet hangs from several ropes and you cut them with your finger, in just the right order and at the right moment, so that it swings into Om Nom's mouth, picking up stars on the way.