Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

please create me a space flight tsimulator in threeJS. thanks

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-5-sonnet-20241022’s answer.
  1. User

    please create me a space flight tsimulator in threeJS. thanks

  2. Assistant

    Absolutely! Below is a basic space flight simulator using Three.js. This example lets you "fly" a spaceship (represented by a simple cone) in 3D space using the keyboard and mouse.

    Features:

    • WASD: Move forward/backward/strafe left/right
    • Mouse: Look around (click to lock pointer)
    • Space/Shift: Move up/down

    1. HTML File

    Save this as index.html and open in your browser.

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Three.js Space Flight Simulator</title>
      <style>
        body { margin: 0; overflow: hidden; background: black; }
        #info { position: absolute; top: 10px; left: 10px; color: white; z-index: 1; }
      </style>
    </head>
    <body>
      <div id="info">
        <b>Space Flight Simulator</b><br>
        WASD: Move<br>
        Mouse: Look<br>
        Space/Shift: Up/Down<br>
        Click to lock pointer
      </div>
      <script type="module">
        import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.153.0/build/three.module.js';
    
        // Scene, Camera, Renderer
        const scene = new THREE.Scene();
        scene.background = new THREE.Color(0x000010);
    
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 10000);
        camera.position.set(0, 0, 10);
    
        const renderer = new THREE.WebGLRenderer({antialias: true});
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
    
        // Starfield
        const starGeometry = new THREE.BufferGeometry();
        const starCount = 2000;
        const starVertices = [];
        for (let i = 0; i < starCount; i++) {
          const x = (Math.random() - 0.5) * 2000;
          const y = (Math.random() - 0.5) * 2000;
          const z = (Math.random() - 0.5) * 2000;
          starVertices.push(x, y, z);
        }
        starGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starVertices, 3));
        const starMaterial = new THREE.PointsMaterial({ color: 0xffffff, size: 1 });
        const stars = new THREE.Points(starGeometry, starMaterial);
        scene.add(stars);
    
        // Spaceship (simple cone)
        const shipGeometry = new THREE.ConeGeometry(1, 3, 16);
        const shipMaterial = new THREE.MeshPhongMaterial({ color: 0x00ffcc });
        const ship = new THREE.Mesh(shipGeometry, shipMaterial);
        ship.rotation.x = Math.PI / 2;
        scene.add(ship);
    
        // Light
        const light = new THREE.PointLight(0xffffff, 1, 100);
        light.position.set(0, 10, 10);
        scene.add(light);
    
        // Controls
        let velocity = new THREE.Vector3();
        let direction = new THREE.Vector3();
        let moveForward = false, moveBackward = false, moveLeft = false, moveRight = false, moveUp = false, moveDown = false;
        let canMove = false;
    
        // Pointer Lock
        renderer.domElement.addEventListener('click', () => {
          renderer.domElement.requestPointerLock();
        });
    
        let pitch = 0, yaw = 0;
        document.addEventListener('pointerlockchange', () => {
          canMove = document.pointerLockElement === renderer.domElement;
        });
    
        document.addEventListener('mousemove', (event) => {
          if (!canMove) return;
          yaw -= event.movementX * 0.002;
          pitch -= event.movementY * 0.002;
          pitch = Math.max(-Math.PI/2, Math.min(Math.PI/2, pitch));
        });
    
        // Keyboard
        document.addEventListener('keydown', (event) => {
          switch(event.code) {
            case 'KeyW': moveForward = true; break;
            case 'KeyS': moveBackward = true; break;
            case 'KeyA': moveLeft = true; break;
            case 'KeyD': moveRight = true; break;
            case 'Space': moveUp = true; break;
            case 'ShiftLeft': moveDown = true; break;
          }
        });
        document.addEventListener('keyup', (event) => {
          switch(event.code) {
            case 'KeyW': moveForward = false; break;
            case 'KeyS': moveBackward = false; break;
            case 'KeyA': moveLeft = false; break;
            case 'KeyD': moveRight = false; break;
            case 'Space': moveUp = false; break;
            case 'ShiftLeft': moveDown = false; break;
          }
        });
    
        // Animation Loop
        function animate() {
          requestAnimationFrame(animate);
    
          // Update direction
          direction.set(0, 0, 0);
          if (moveForward) direction.z -= 1;
          if (moveBackward) direction.z += 1;
          if (moveLeft) direction.x -= 1;
          if (moveRight) direction.x += 1;
          if (moveUp) direction.y += 1;
          if (moveDown) direction.y -= 1;
          direction.normalize();
    
          // Rotate camera and ship
          camera.rotation.order = 'YXZ';
          camera.rotation.y = yaw;
          camera.rotation.x = pitch;
    
          // Move camera
          const speed = 0.5;
          const move = new THREE.Vector3(direction.x, direction.y, direction.z);
          move.applyEuler(camera.rotation);
          camera.position.add(move.multiplyScalar(speed));
    
          // Move ship to camera
          ship.position.copy(camera.position);
          ship.rotation.set(camera.rotation.x + Math.PI/2, camera.rotation.y, camera.rotation.z);
    
          renderer.render(scene, camera);
        }
        animate();
    
        // Responsive
        window.addEventListener('resize', () => {
          camera.aspect = window.innerWidth / window.innerHeight;
          camera.updateProjectionMatrix();
          renderer.setSize(window.innerWidth, window.innerHeight);
        });
      </script>
    </body>
    </html>
    

    2. How to Use

    1. Copy the code above into a file named index.html.
    2. Open it in your browser.
    3. Click anywhere to lock the pointer and start flying.
    4. Use WASD to move, mouse to look, Space/Shift to move up/down.

    You can expand this with planets, HUD, physics, etc. Let me know if you want more features!

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