Skip to content
The Chat Archive
chatgpt-4o-latest-20250326· OpenAI LMArena Human Preference 140K

web dev: create a 3d racing game in one file, no npm stuff. synthwave aesthetic

  1. User

    web dev: create a 3d racing game in one file, no npm stuff. synthwave aesthetic

  2. Assistant

    Sure! Below is a minimal 3D racing game in one HTML file, using three.js via CDN, with a synthwave aesthetic. It requires no npm or build tools, just drop it into a .html file and open in your browser.


    🚗 Features:

    • 3D car model (basic box)
    • Infinite road illusion
    • Neon-style synthwave colors
    • WASD/arrow key controls

    ✅ How to Use:

    1. Create a file called synthwave-racer.html.
    2. Paste the code below.
    3. Open in your browser.

    🎮 One-File Synthwave 3D Racing Game

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Synthwave Racer</title>
      <style>
        html, body { margin: 0; overflow: hidden; background: black; }
        canvas { display: block; }
      </style>
    </head>
    <body>
      <script src="https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.min.js"></script>
      <script>
        // ==== SETUP SCENE ====
        const scene = new THREE.Scene();
        scene.fog = new THREE.Fog(0x0a0a1f, 10, 100);
    
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 1000);
        camera.position.set(0, 5, 10);
        camera.lookAt(0, 0, 0);
    
        const renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
    
        // ==== LIGHTING ====
        const ambientLight = new THREE.AmbientLight(0xff00ff, 0.5);  // synthwave pink
        scene.add(ambientLight);
    
        const dirLight = new THREE.DirectionalLight(0x00ffff, 1);    // synthwave cyan
        dirLight.position.set(0, 20, 10);
        scene.add(dirLight);
    
        // ==== GROUND ====
        const roadMaterial = new THREE.MeshStandardMaterial({ color: 0x111122, metalness: 0.3, roughness: 0.7 });
        const road = new THREE.Mesh(new THREE.PlaneGeometry(20, 1000), roadMaterial);
        road.rotation.x = -Math.PI / 2;
        road.position.z = -500;
        scene.add(road);
    
        // ==== CAR ====
        const car = new THREE.Group();
        const body = new THREE.Mesh(new THREE.BoxGeometry(1, 0.5, 2), new THREE.MeshStandardMaterial({ color: 0xff00ff }));
        body.position.y = 0.25;
        car.add(body);
        car.position.y = 0.25;
        scene.add(car);
    
        // ==== LINES ON ROAD ====
        const lineMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00 }); // neon yellow
        for (let i = 0; i < 100; i++) {
          const line = new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.01, 4), lineMaterial);
          line.position.set(0, 0.01, -i * 10);
          scene.add(line);
        }
    
        // ==== MOVEMENT ====
        const keys = {};
        window.addEventListener('keydown', e => keys[e.key.toLowerCase()] = true);
        window.addEventListener('keyup', e => keys[e.key.toLowerCase()] = false);
    
        let roadSpeed = 0.5;
    
        // ==== ANIMATION LOOP ====
        function animate() {
          requestAnimationFrame(animate);
    
          // Controls
          if (keys['a'] || keys['arrowleft'])  car.position.x -= 0.2;
          if (keys['d'] || keys['arrowright']) car.position.x += 0.2;
          car.position.x = THREE.MathUtils.clamp(car.position.x, -8, 8);
    
          // Infinite road effect by moving road lines
          scene.children.forEach(obj => {
            if (obj.geometry && obj.geometry.type === 'BoxGeometry' && obj !== car) {
              obj.position.z += roadSpeed;
              if (obj.position.z > 10) obj.position.z = -1000;
            }
          });
    
          // Camera follow
          camera.position.x = car.position.x * 0.5;
          camera.lookAt(car.position.x, 0, car.position.z);
    
          renderer.render(scene, camera);
        }
    
        animate();
    
        // ==== HANDLE RESIZE ====
        window.addEventListener('resize', () => {
          camera.aspect = window.innerWidth/window.innerHeight;
          camera.updateProjectionMatrix();
          renderer.setSize(window.innerWidth, window.innerHeight);
        });
      </script>
    </body>
    </html>
    

    🎨 Synthwave Aesthetic Tips:

    • Use neon pinks, purples, cyans, yellows
    • Dark background (#000011, #0a0a1f)
    • Simple geometry with glow-like colors
    • Use fog and directional lighting for depth

    🔧 Want to Enhance It?

    • Add collision and obstacles
    • Use particle effects for tail lights
    • Add synthwave BGM via <audio>
    • Starscape skybox
    • Trail shaders

    Want a shader-style neon grid ground like in Tron? Let me know and I’ll show you how!

    Enjoy building your synth-racer! ✨

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.