Creating a 3D endless FPS platformer with a working leveling system using only HTML + JavaScript (no textures, models, or external files) is a challenging but fun project. We'll use the Three.js library (included via CDN) to handle 3D rendering and basic physics.
Below is a single-file implementation that includes:
A first-person camera controller
Infinite procedural platforms
Simple jumping mechanics
A leveling system based on distance traveled
Basic collision detection
✅ How it works:
The player moves forward automatically.
Use WASD to move side-to-side and jump.
Platforms are generated in front of the player as they move.
Level increases every time the player travels a set distance.
📄 Single HTML File: Copy & Paste into .html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>3D Endless FPS Platformer</title>
<style>
body { margin: 0; overflow: hidden; background: #000; }
canvas { display: block; }
#ui {
position: absolute;
top: 10px;
left: 10px;
color: white;
font-family: sans-serif;
z-index: 2;
}
</style>
</head>
<body>
<div id="ui">
<p>Level: <span id="level">1</span></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.160.0/examples/js/controls/PointerLockControls.js"></script>
<script>
let scene, camera, renderer, controls;
let player, velocity = new THREE.Vector3();
let keys = {};
let canJump = false;
let level = 1;
let distanceTraveled = 0;
const levelDistance = 50;
const platforms = [];
const platformSize = 10;
const maxPlatforms = 10;
let lastPlatformZ = 0;
init();
animate();
function init() {
// Scene setup
scene = new THREE.Scene();
scene.background = new THREE.Color(0x202020);
camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Lighting
const light = new THREE.HemisphereLight(0xffffff, 0x444444);
light.position.set(0, 200, 0);
scene.add(light);
// Controls
controls = new THREE.PointerLockControls(camera, document.body);
document.body.addEventListener('click', () => controls.lock());
// Player
const geometry = new THREE.BoxGeometry(1, 2, 1);
const material = new THREE.MeshStandardMaterial({color: 0x00ff00});
player = new THREE.Mesh(geometry, material);
player.position.y = 1;
scene.add(player);
// Ground platform
createPlatform(0, 0, 0);
// Input
document.addEventListener('keydown', e => keys[e.code] = true);
document.addEventListener('keyup', e => keys[e.code] = false);
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
}
function createPlatform(x, y, z) {
const geo = new THREE.BoxGeometry(platformSize, 1, platformSize);
const mat = new THREE.MeshStandardMaterial({color: 0xaaaaaa});
const plat = new THREE.Mesh(geo, mat);
plat.position.set(x, y, z);
scene.add(plat);
platforms.push(plat);
}
function updateLevel() {
const newLevel = Math.floor(distanceTraveled / levelDistance) + 1;
if (newLevel > level) {
level = newLevel;
document.getElementById("level").innerText = level;
generateNewPlatforms(); // Add more platforms
}
}
function generateNewPlatforms() {
for (let i = 0; i < 3; i++) {
const x = (Math.random() - 0.5) * platformSize * 1.5;
lastPlatformZ -= platformSize;
createPlatform(x, 0, lastPlatformZ);
}
}
function animate() {
requestAnimationFrame(animate);
const delta = 0.1;
const speed = 0.1 * level;
// Move forward
velocity.z = -speed;
// Side movement
if (keys['KeyA']) velocity.x = -0.1;
if (keys['KeyD']) velocity.x = 0.1;
// Jump
if (keys['Space'] && canJump) {
velocity.y = 0.2;
canJump = false;
}
// Gravity
velocity.y -= 0.01;
// Apply movement
player.position.add(velocity);
// Collision with ground/platforms
let onGround = false;
for (const p of platforms) {
const box = new THREE.Box3().setFromObject(p);
if (box.containsPoint(player.position)) {
// Snap to top of platform
player.position.y = box.max.y + 1;
velocity.y = 0;
onGround = true;
break;
}
}
if (onGround) canJump = true;
else canJump = false;
// Update distance
distanceTraveled += Math.abs(velocity.z);
updateLevel();
// Camera follows player
controls.getObject().position.copy(player.position).add(new THREE.Vector3(0, 1, 5));
renderer.render(scene, camera);
}
</script>
</body>
</html>
🎮 Controls
Click anywhere to capture mouse and start playing.
WASD: Move left/right, jump.
Mouse: Look around.
🔧 Features Summary
Feature
Description
Endless Movement
Player auto-moves forward; platforms spawn ahead.
FPS Camera
First-person view using PointerLockControls.
Jumping
Spacebar jumps if on solid ground.
Level System
Level increases per distance traveled.
No External Files
Uses only Three.js CDN; no images/models.
🚀 Tips for Expansion
You can expand this game by:
Adding enemies or obstacles
Implementing score tracking
Increasing difficulty per level
Using sound effects
Improving collision detection
Let me know if you want any of those features added!