Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-5-sonnet-20241022· AnthropicHugging 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 gpt-4.1-2025-04-14’s answer.
  1. User

    please create me a space flight tsimulator in threeJS. thanks

  2. Claude Assistant

    Here's a basic space flight simulator using Three.js. This example includes a spaceship that you can control with keyboard inputs and some basic stars in the background:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Space Flight Simulator</title>
        <style>
            body { margin: 0; }
            canvas { display: block; }
        </style>
    </head>
    <body>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
        <script>
            let scene, camera, renderer;
            let spaceship;
            let velocity = new THREE.Vector3();
            let rotation = new THREE.Vector3();
            
            // Initialize the scene
            function init() {
                scene = new THREE.Scene();
                camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
                
                renderer = new THREE.WebGLRenderer();
                renderer.setSize(window.innerWidth, window.innerHeight);
                document.body.appendChild(renderer.domElement);
    
                // Create spaceship
                const geometry = new THREE.ConeGeometry(1, 4, 8);
                const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
                spaceship = new THREE.Mesh(geometry, material);
                scene.add(spaceship);
    
                // Create stars
                createStars();
    
                // Position camera
                camera.position.z = 10;
    
                // Add event listeners for keyboard controls
                document.addEventListener('keydown', onKeyDown);
                document.addEventListener('keyup', onKeyUp);
    
                // Handle window resizing
                window.addEventListener('resize', onWindowResize, false);
            }
    
            // Create background stars
            function createStars() {
                const starsGeometry = new THREE.BufferGeometry();
                const starsMaterial = new THREE.PointsMaterial({
                    color: 0xFFFFFF,
                    size: 0.1
                });
    
                const starsVertices = [];
                for (let i = 0; i < 1000; i++) {
                    const x = (Math.random() - 0.5) * 2000;
                    const y = (Math.random() - 0.5) * 2000;
                    const z = (Math.random() - 0.5) * 2000;
                    starsVertices.push(x, y, z);
                }
    
                starsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starsVertices, 3));
                const starField = new THREE.Points(starsGeometry, starsMaterial);
                scene.add(starField);
            }
    
            // Handle keyboard inputs
            function onKeyDown(event) {
                switch(event.keyCode) {
                    case 87: // W
                        velocity.z = -0.1;
                        break;
                    case 83: // S
                        velocity.z = 0.1;
                        break;
                    case 65: // A
                        velocity.x = -0.1;
                        break;
                    case 68: // D
                        velocity.x = 0.1;
                        break;
                    case 38: // Up arrow
                        rotation.x = -0.02;
                        break;
                    case 40: // Down arrow
                        rotation.x = 0.02;
                        break;
                    case 37: // Left arrow
                        rotation.y = -0.02;
                        break;
                    case 39: // Right arrow
                        rotation.y = 0.02;
                        break;
                }
            }
    
            function onKeyUp(event) {
                switch(event.keyCode) {
                    case 87: // W
                    case 83: // S
                        velocity.z = 0;
                        break;
                    case 65: // A
                    case 68: // D
                        velocity.x = 0;
                        break;
                    case 38: // Up arrow
                    case 40: // Down arrow
                        rotation.x = 0;
                        break;
                    case 37: // Left arrow
                    case 39: // Right arrow
                        rotation.y = 0;
                        break;
                }
            }
    
            // Handle window resizing
            function onWindowResize() {
                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();
                renderer.setSize(window.innerWidth, window.innerHeight);
            }
    
            // Animation loop
            function animate() {
                requestAnimationFrame(animate);
    
                // Update spaceship position and rotation
                spaceship.position.add(velocity);
                spaceship.rotation.x += rotation.x;
                spaceship.rotation.y += rotation.y;
    
                // Update camera position to follow spaceship
                camera.position.x = spaceship.position.x;
                camera.position.y = spaceship.position.y;
                camera.position.z = spaceship.position.z + 10;
    
                renderer.render(scene, camera);
            }
    
            // Start the simulation
            init();
            animate();
        </script>
    </body>
    </html>
    

    This simulator includes:

    1. A simple green cone representing the spaceship
    2. Background stars for visual reference
    3. Basic controls:
      • W/S: Move forward/backward
      • A/D: Move left/right
      • Arrow keys: Rotate the spaceship
    4. Camera following the spaceship
    5. Responsive window resizing

    To use the simulator:

    1. Save the code as an HTML file
    2. Open it in a modern web browser
    3. Use the keyboard controls to fly the spaceship

    You can enhance this basic simulator by:

    1. Adding more detailed spaceship models
    2. Implementing more realistic physics
    3. Adding planets or other space objects
    4. Improving the lighting and materials
    5. Adding particle effects for engine thrust
    6. Implementing collision detection
    7. Adding a heads-up display (HUD)
    8. Including sound effects

    Remember that this is a basic implementation, and you can build upon it to create a more complex and realistic space flight simulator.

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