Portrait 3D Game Series · Three.js Arcade Starter

How to Build a 3D Rocket Lander Game in Three.js

Want to build your own version of Rocket Lander? This step-by-step Three.js tutorial walks through the exact arcade loop behind our portrait mobile game — hold-to-thrust gravity, drag-to-steer controls, a moving neon landing pad, pooled thruster sparks, and soft-landing velocity checks with zero external physics engine.

Play Rocket Lander

Build & Customize Faster

Want to Modify This Game and Publish One Yourself?

Change gravity, swap rocket colors, speed up the moving pad, or build your own space theme. Grab the free standalone starter code below, or join Indie Forge Studio Membership to unlock our interactive Live Code Editor, premium Three.js tutorials, and ad-free play across every game.

How Does a Three.js Portrait Rocket Lander Work? (Quick Answer)

Instead of loading a heavy physics engine, a mobile-first Three.js Rocket Lander runs on lightweight custom kinematics: apply downward gravity every frame, add upward thrust while the player holds the screen (or Space), apply damped horizontal steering from pointer drag or arrow keys, and test three values at touchdown — pad alignment, vertical impact speed, and tilt angle.

What You Need

  • Any modern browser and a plain text editor — no build step or bundler required.
  • Basic familiarity with a Three.js scene, camera, and requestAnimationFrame loop.
  • Want rigid-body collisions and breakaway crash debris instead of lightweight arcade math? Check out my Rapier Physics Rocket Lander tutorial.

Step 1: Portrait-First Scene, Capped DPR & Single-Draw Starfield

Portrait mobile games live or die on fast startup and steady 60 FPS on phones. Cap devicePixelRatio at 1.75 so high-DPI phones do not melt their GPUs, frame the camera slightly above the landing zone, and draw all background stars in a single THREE.Points call.

const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, powerPreference: 'high-performance' });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;

const camera = new THREE.PerspectiveCamera(48, window.innerWidth / window.innerHeight, 0.1, 120);
camera.position.set(0, 4.8, 15.5);
camera.lookAt(0, 3.6, 0);

// 450 stars in one draw call
const starPos = new Float32Array(450 * 3);
for (let i = 0; i < 450; i++) {
  starPos[i * 3] = (Math.random() - 0.5) * 46;
  starPos[i * 3 + 1] = Math.random() * 26 - 2;
  starPos[i * 3 + 2] = -6 - Math.random() * 24;
}
const starGeo = new THREE.BufferGeometry();
starGeo.setAttribute('position', new THREE.BufferAttribute(starPos, 3));
scene.add(new THREE.Points(starGeo, new THREE.PointsMaterial({ color: 0xcfe9ff, size: 0.14 })));

Step 2: Low-Poly 3D Rocket & Pooled Thruster Sparks

Building the rocket from lightweight Three.js primitives (cylinder hull, cone nose, three rotated fins, and a flickering thruster cone) avoids external model downloads so the game opens instantaneously. For the exhaust sparks, pre-allocate a 70-particle ring buffer and overwrite the oldest slot — zero garbage collection spikes mid-flight.

const rocket = new THREE.Group();
const hull = new THREE.Mesh(new THREE.CylinderGeometry(0.32, 0.42, 1.55, 16), bodyMat);
hull.position.y = 0.95;
rocket.add(hull);

const nose = new THREE.Mesh(new THREE.ConeGeometry(0.32, 0.62, 16), accentMat);
nose.position.y = 2.03;
rocket.add(nose);

for (let i = 0; i < 3; i++) {
  const angle = (i * Math.PI * 2) / 3;
  const fin = new THREE.Mesh(new THREE.BoxGeometry(0.08, 0.52, 0.36), accentMat);
  fin.position.set(Math.sin(angle) * 0.42, 0.42, Math.cos(angle) * 0.42);
  fin.rotation.y = angle;
  rocket.add(fin);
}

// Ring-buffer particle emitter (no per-frame allocations)
function emitSpark(wx, wy) {
  const p = pVel[pCursor];
  pPos[pCursor * 3] = wx + (Math.random() - 0.5) * 0.16;
  pPos[pCursor * 3 + 1] = wy;
  pPos[pCursor * 3 + 2] = (Math.random() - 0.5) * 0.16;
  p.x = (Math.random() - 0.5) * 1.4;
  p.y = -3.8 - Math.random() * 2.2;
  p.life = 0.28 + Math.random() * 0.22;
  pCursor = (pCursor + 1) % MAX_P;
}

Step 3: Hold-to-Thrust Gravity & Unified Touch/Keyboard Steering

The secret to a great one-thumb portrait game is unifying touch and keyboard into two clean inputs: firing (boolean) and steer (-1 to +1). Exponential damping (Math.pow(0.32, dt)) keeps lateral drift frame-rate independent across 60Hz and 120Hz displays.

const GRAVITY = -6.2;
const THRUST = 13.8;
const STEER_ACCEL = 8.4;

const steer = (keys.right ? 1 : 0) - (keys.left ? 1 : 0)
  + (pointerDown ? THREE.MathUtils.clamp(pointerSteer * 1.6, -1, 1) : 0);
const firing = (keys.thrust || pointerDown) && fuel > 0;

vy += GRAVITY * dt;
if (firing) {
  vy += THRUST * dt;
  fuel = Math.max(0, fuel - 24 * dt);
}
vx += steer * STEER_ACCEL * dt;
vx *= Math.pow(0.32, dt);

rx = THREE.MathUtils.clamp(rx + vx * dt, -5.8, 5.8);
ry += vy * dt;
tilt = THREE.MathUtils.lerp(tilt, THREE.MathUtils.clamp(-steer * 0.32, -0.38, 0.38), 1 - Math.exp(-10 * dt));

Step 4: Moving Landing Pad & Soft-Landing Velocity Check

Drive the pad horizontally with a sine wave whose frequency and range climb with each level. When the rocket reaches the pad plane (ry <= 0.24), test all three landing conditions: within the scaled pad radius, vertical speed under 3.6, and tilt nearly upright.

padPhase += dt * (0.75 + level * 0.16);
padX = Math.sin(padPhase) * Math.min(4.2, 1.8 + level * 0.4);
padGroup.position.x = padX;

if (ry <= 0.24) {
  ry = 0.24;
  const padRadius = 1.45 * padGroup.scale.x;
  const onPad = Math.abs(rx - padX) <= padRadius;
  const soft = Math.abs(vy) <= 3.6 && Math.abs(tilt) <= 0.34;
  if (onPad && soft) {
    score += 100 + Math.round(fuel) * 2 + level * 25;
    padRing.material.color.setHex(0x4ade80);
  } else {
    padRing.material.color.setHex(0xef4444);
  }
}

Step 5: Progressive Difficulty & Zero-Asset Web Audio

Shrink the pad scale by 7% per level (clamped at 0.65) so early landings teach the timing and later rounds demand precision. Synthesizing landing chimes and crash rumbles with AudioContext oscillators keeps your entire game under a few kilobytes with zero MP3 files to preload.

function beep(freq, dur, type = 'triangle', slide = 0) {
  const o = actx.createOscillator(), g = actx.createGain(), t = actx.currentTime;
  o.type = type;
  o.frequency.setValueAtTime(freq, t);
  if (slide) o.frequency.exponentialRampToValueAtTime(Math.max(40, freq + slide), t + dur);
  g.gain.setValueAtTime(0.06, t);
  g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
  o.connect(g).connect(actx.destination);
  o.start(t);
  o.stop(t + dur + 0.02);
}

Complete Single-File Starter Code

Save as rocket-lander.html and open in any browser, or click Launch to test immediately.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>Rocket Lander 3D Starter</title>
  <style>
    html, body { margin: 0; height: 100%; overflow: hidden; background: #05030f; font-family: Inter, system-ui, sans-serif; touch-action: none; }
    canvas { display: block; width: 100%; height: 100%; }
    #hud { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); background: rgba(6,10,20,0.8); color: #e5e7eb; padding: 10px 18px; border-radius: 12px; border: 1px solid rgba(42,209,214,0.4); font-size: 13px; text-align: center; pointer-events: none; }
  </style>
  <script type="importmap">
    { "imports": { "three": "https://unpkg.com/three@0.186.1/build/three.module.js" } }
  </script>
</head>
<body>
  <div id="hud">Hold Space or Touch to Thrust &middot; A/D or Drag to Steer</div>
  <canvas id="c"></canvas>
  <script type="module">
    import * as THREE from 'three';

    const canvas = document.getElementById('c');
    const hud = document.getElementById('hud');
    const renderer = new THREE.WebGLRenderer({ canvas, antialias: true });
    renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.75));
    renderer.setSize(window.innerWidth, window.innerHeight);

    const scene = new THREE.Scene();
    scene.background = new THREE.Color(0x05030f);
    const camera = new THREE.PerspectiveCamera(48, window.innerWidth / window.innerHeight, 0.1, 100);
    camera.position.set(0, 4.8, 15.5);
    camera.lookAt(0, 3.6, 0);

    scene.add(new THREE.HemisphereLight(0x88c8ff, 0x1a1030, 0.9));
    const sun = new THREE.DirectionalLight(0xffffff, 1.3);
    sun.position.set(6, 12, 8);
    scene.add(sun);

    // Moving landing pad
    const pad = new THREE.Group();
    pad.add(new THREE.Mesh(new THREE.CylinderGeometry(1.5, 1.8, 0.3, 24), new THREE.MeshStandardMaterial({ color: 0x1f2937 })));
    const ring = new THREE.Mesh(new THREE.TorusGeometry(1.35, 0.07, 10, 32), new THREE.MeshBasicMaterial({ color: 0x2ad1d6 }));
    ring.rotation.x = Math.PI / 2; ring.position.y = 0.16;
    pad.add(ring);
    scene.add(pad);

    // Low-poly 3D rocket
    const rocket = new THREE.Group();
    const hull = new THREE.Mesh(new THREE.CylinderGeometry(0.32, 0.42, 1.55, 16), new THREE.MeshStandardMaterial({ color: 0xe5edf5 }));
    hull.position.y = 0.95; rocket.add(hull);
    const nose = new THREE.Mesh(new THREE.ConeGeometry(0.32, 0.62, 16), new THREE.MeshStandardMaterial({ color: 0x2ad1d6 }));
    nose.position.y = 2.03; rocket.add(nose);
    const flame = new THREE.Mesh(new THREE.ConeGeometry(0.24, 0.95, 12), new THREE.MeshBasicMaterial({ color: 0xffa43b }));
    flame.rotation.x = Math.PI; flame.position.y = -0.45; rocket.add(flame);
    scene.add(rocket);

    let level = 1, score = 0, fuel = 100, status = 'play', timer = 0;
    let rx = 0, ry = 8.5, vx = 0, vy = 0, tilt = 0, padPhase = 0;
    const keys = { thrust: false, left: false, right: false };
    let pointerDown = false, pointerSteer = 0;

    function reset(next) {
      if (next) level++; else { level = 1; score = 0; }
      rx = (Math.random() - 0.5) * 4; ry = 8.5; vx = 0; vy = 0; tilt = 0; fuel = 100; status = 'play';
      const s = Math.max(0.65, 1.05 - (level - 1) * 0.07);
      pad.scale.set(s, 1, s);
      ring.material.color.setHex(0x2ad1d6);
    }

    window.addEventListener('keydown', e => {
      const k = e.key.toLowerCase();
      if (k === ' ' || k === 'w' || k === 'arrowup') keys.thrust = true;
      if (k === 'a' || k === 'arrowleft') keys.left = true;
      if (k === 'd' || k === 'arrowright') keys.right = true;
    });
    window.addEventListener('keyup', e => {
      const k = e.key.toLowerCase();
      if (k === ' ' || k === 'w' || k === 'arrowup') keys.thrust = false;
      if (k === 'a' || k === 'arrowleft') keys.left = false;
      if (k === 'd' || k === 'arrowright') keys.right = false;
    });
    canvas.addEventListener('pointerdown', e => { pointerDown = true; pointerSteer = ((e.clientX / innerWidth) - 0.5) * 2; });
    window.addEventListener('pointermove', e => { if (pointerDown) pointerSteer = ((e.clientX / innerWidth) - 0.5) * 2; });
    window.addEventListener('pointerup', () => { pointerDown = false; pointerSteer = 0; });
    window.addEventListener('resize', () => { camera.aspect = innerWidth / innerHeight; camera.updateProjectionMatrix(); renderer.setSize(innerWidth, innerHeight); });

    let last = performance.now();
    function loop(now) {
      requestAnimationFrame(loop);
      const dt = Math.min(0.05, (now - last) / 1000); last = now;
      padPhase += dt * (0.75 + level * 0.16);
      const padX = Math.sin(padPhase) * Math.min(4.2, 1.8 + level * 0.4);
      pad.position.x = padX;

      if (status === 'play') {
        const steer = (keys.right ? 1 : 0) - (keys.left ? 1 : 0) + (pointerDown ? THREE.MathUtils.clamp(pointerSteer * 1.6, -1, 1) : 0);
        const firing = (keys.thrust || pointerDown) && fuel > 0;
        vy += -6.2 * dt + (firing ? 13.8 * dt : 0);
        if (firing) fuel = Math.max(0, fuel - 24 * dt);
        vx = (vx + steer * 8.4 * dt) * Math.pow(0.32, dt);
        rx = THREE.MathUtils.clamp(rx + vx * dt, -5.8, 5.8);
        ry += vy * dt;
        tilt = THREE.MathUtils.lerp(tilt, THREE.MathUtils.clamp(-steer * 0.32, -0.38, 0.38), 1 - Math.exp(-10 * dt));
        flame.visible = firing;

        if (ry <= 0.24) {
          ry = 0.24; flame.visible = false;
          const ok = Math.abs(rx - padX) <= 1.45 * pad.scale.x && Math.abs(vy) <= 3.6 && Math.abs(tilt) <= 0.34;
          status = ok ? 'landed' : 'crashed'; timer = 1.4;
          if (ok) score += 100 + Math.round(fuel) * 2;
          ring.material.color.setHex(ok ? 0x4ade80 : 0xef4444);
          hud.textContent = ok ? 'SOFT LANDING! Score: ' + score : 'CRASHED! Try again...';
        } else {
          hud.textContent = 'LVL ' + level + ' | SCORE ' + score + ' | FUEL ' + Math.round(fuel) + '%';
        }
      } else {
        timer -= dt;
        if (timer <= 0) reset(status === 'landed');
      }

      rocket.position.set(rx, ry, 0);
      rocket.rotation.z = tilt;
      renderer.render(scene, camera);
    }
    requestAnimationFrame(loop);
  </script>
</body>
</html>

Frequently Asked Questions

Do I need a physics engine like Rapier or Cannon.js to build a 3D Rocket Lander?

No. For a fast-loading portrait arcade game, custom velocity integration (gravity, upward thrust, horizontal damping, and a pad-plane touchdown check) gives tighter mobile feel and opens instantly with zero WASM overhead.

How do you make Rocket Lander controls feel good on both phones and desktop?

Map pointerdown and pointermove across the canvas to simultaneous thrust and horizontal steering while keeping Space, W, and Arrow keys active on desktop. Both inputs feed the exact same steer and firing variables.

How does soft-landing detection work?

When the rocket reaches the pad top, check three thresholds: horizontal distance from the pad center is within the scaled pad radius, absolute vertical speed is below 3.6 units per second, and tilt angle is nearly upright.

Can I modify this Rocket Lander code and publish my own version?

Yes. Copy or launch the standalone starter code above, customize the physics, rocket geometry, and level curve, or become an Indie Forge Studio member to unlock the interactive Live Code Editor and premium Three.js tutorials.