Below is a self-contained, copy-pasteable HTML file that uses the ES-module build of Three.js (no bundler needed).
Open it in any modern browser and you’ll see a goofy little quadruped that procedurally walks in place.
Everything (geometry + motion) is generated on the fly—there are no key-framed clips or external assets.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Procedural Walker – Three.js</title>
<style>
body { margin: 0; background:#202020; overflow:hidden; }
canvas { display:block; }
</style>
</head>
<body>
<script type="module">
/* ─────────────────────────────────────────────────────────────
IMPORTS
────────────────────────────────────────────────────────────── */
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.162.0/build/three.module.js';
import {OrbitControls} from 'https://cdn.jsdelivr.net/npm/three@0.162.0/examples/jsm/controls/OrbitControls.js';
/* ─────────────────────────────────────────────────────────────
BASIC SCENE SETUP
────────────────────────────────────────────────────────────── */
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x202020);
const camera = new THREE.PerspectiveCamera(45, innerWidth/innerHeight, 0.1, 100);
camera.position.set(4, 3, 6);
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(devicePixelRatio);
document.body.appendChild(renderer.domElement);
const controls = new OrbitControls(camera, renderer.domElement);
controls.target.set(0,1,0);
controls.update();
/* LIGHTS */
scene.add(new THREE.HemisphereLight(0xffffff, 0x444444, 1.0));
const dirLight = new THREE.DirectionalLight(0xffffff, 0.6);
dirLight.position.set(3, 10, 5);
scene.add(dirLight);
/* ─────────────────────────────────────────────────────────────
CREATURE BLUEPRINT
────────────────────────────────────────────────────────────── */
const CREATURE = new THREE.Group();
scene.add(CREATURE);
const matBody = new THREE.MeshStandardMaterial({color:0x99c2ff, flatShading:true});
const matLeg = new THREE.MeshStandardMaterial({color:0xd9a066, flatShading:true});
const matFoot = new THREE.MeshStandardMaterial({color:0x333333, roughness:0.8});
const sphere = new THREE.SphereGeometry(0.6, 12, 12);
const cylUpper = new THREE.CylinderGeometry(0.12, 0.16, 0.8, 8);
const cylLower = new THREE.CylinderGeometry(0.10, 0.12, 0.7, 8);
const boxFoot = new THREE.BoxGeometry(0.25, 0.15, 0.4);
/* BODY */
const body = new THREE.Mesh(sphere, matBody);
body.position.y = 1.2;
CREATURE.add(body);
/* helper to create one leg -------------------------------------------------- */
function buildLeg(sideSign=1, isFront=true){
const upper = new THREE.Mesh(cylUpper, matLeg);
const lower = new THREE.Mesh(cylLower, matLeg);
const foot = new THREE.Mesh(boxFoot, matFoot);
/* PIVOT hierarchy: hip → knee → ankle (foot) */
const hip = new THREE.Group();
const knee = new THREE.Group();
const ankle = new THREE.Group();
hip.add(upper);
upper.position.y = -0.4; // center cylinder
knee.position.y = -0.8; // bottom of upper
knee.add(lower);
lower.position.y = -0.35;
ankle.position.y = -0.7;
ankle.add(foot);
foot.position.y = -0.075;
foot.position.z = 0.1;
hip.add(knee);
knee.add(ankle);
/* Placement on body */
const offsetX = 0.45 * sideSign;
const offsetZ = isFront ? 0.35 : -0.35;
hip.position.set(offsetX, 0.8, offsetZ);
body.add(hip);
/* return all driven nodes so we can animate easily */
return {hip,knee,ankle,foot, phase: (isFront?0 : Math.PI) + (sideSign>0?0:Math.PI)};
}
/* Build 4 legs */
const legs = [
buildLeg(+1, true), // front right
buildLeg(-1, true), // front left
buildLeg(+1, false), // back right
buildLeg(-1, false) // back left
];
/* ─────────────────────────────────────────────────────────────
ANIMATION LOOP
────────────────────────────────────────────────────────────── */
let clock = new THREE.Clock();
function animate(){
const t = clock.getElapsedTime();
const walkSpeed = 2.5; // steps per second
const step = t * walkSpeed;
/* BODY BOB */
body.position.y = 1.2 + Math.sin(step*2)*0.05;
body.rotation.z = Math.sin(step*2)*0.05;
body.rotation.x = Math.sin(step*2 + Math.PI/2)*0.04;
/* Each leg gets a phase-shifted pendulum swing */
legs.forEach(leg=>{
const stride = Math.sin(step + leg.phase);
const knee = Math.sin(step + leg.phase + Math.PI/2);
/* hip swing forward/back */
leg.hip.rotation.x = THREE.MathUtils.degToRad(25) * stride;
/* knee bend (delayed) */
leg.knee.rotation.x = THREE.MathUtils.degToRad(30) * knee - 0.2;
/* ankle for foot roll */
leg.ankle.rotation.x = THREE.MathUtils.degToRad(-20) * knee;
/* optional foot banking */
leg.foot.rotation.z = THREE.MathUtils.degToRad(10) * Math.sin(step*2);
});
controls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
/* ─────────────────────────────────────────────────────────────
HANDLE RESIZE
────────────────────────────────────────────────────────────── */
addEventListener('resize', ()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
What makes it “procedural”?
• No baked keyframes—joint angles are pure sine & cosine functions that vary with time.
• Phase offsets (leg.phase) make opposing legs alternate, producing a convincing gait.
• Body bob and subtle rotations are also math-driven.
Feel free to tinker!
• Change walkSpeed, geometry sizes, or add more sine harmonics for fancy swagger.
• Swap the simple geometry with custom meshes but keep the same pivot hierarchy.
• Instead of walking in place, translate the root (CREATURE.position.z -= speed*delta) for forward motion, and add a ground plane for reference.