awesome, can you pllease add perhaps a cooler design for the spacecraft? as well as…
- User
awesome, can you pllease add perhaps a cooler design for the spacecraft? as well as maybe more different sized objects and perhaps slightly more realsitic less polygon like
- Assistant
Absolutely! Let's enhance the space flight simulator with:
✅ A cooler spaceship design (composed of multiple parts for a more "ship-like" look)
✅ More realistic space objects (planets, asteroids) with varied sizes and smoother geometry
✅ Improved materials and lighting for a more immersive feel🛠️ We'll still use only Three.js and built-in geometry for simplicity, but the result will look much better.
👇 Copy and paste the following into your index.html file:
🚀 Enhanced Space Flight Simulator (with improved ship and objects)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Three.js Space Flight Simulator - Cool Ship</title> <style> body { margin: 0; overflow: hidden; background: black; } #info { position: absolute; top: 10px; left: 10px; color: white; font-family: sans-serif; z-index: 1; } </style> </head> <body> <div id="info"> <b>🚀 Space Flight Simulator</b><br> WASD: Move | Mouse: Look<br> Space/Shift: Up/Down<br> V: Toggle View (1st/3rd Person)<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 & Renderer const scene = new THREE.Scene(); scene.background = new THREE.Color(0x000010); const renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // Camera const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 10000); scene.add(camera); // Lighting const ambientLight = new THREE.AmbientLight(0x404040); const pointLight = new THREE.PointLight(0xffffff, 1, 0); pointLight.position.set(50, 50, 50); scene.add(ambientLight, pointLight); // Starfield const starGeometry = new THREE.BufferGeometry(); const starCount = 5000; const starVertices = []; for (let i = 0; i < starCount; i++) { const x = (Math.random() - 0.5) * 5000; const y = (Math.random() - 0.5) * 5000; const z = (Math.random() - 0.5) * 5000; 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 Group const spaceship = new THREE.Group(); scene.add(spaceship); // Cool Spaceship Design const shipMaterial = new THREE.MeshStandardMaterial({ color: 0x00ccff, metalness: 0.6, roughness: 0.3 }); // Body const body = new THREE.CylinderGeometry(0.5, 0.5, 4, 32); const bodyMesh = new THREE.Mesh(body, shipMaterial); bodyMesh.rotation.z = Math.PI / 2; spaceship.add(bodyMesh); // Nose const nose = new THREE.ConeGeometry(0.5, 1.5, 32); const noseMesh = new THREE.Mesh(nose, shipMaterial); noseMesh.position.x = 2.75; noseMesh.rotation.z = Math.PI / 2; spaceship.add(noseMesh); // Wings const wingGeo = new THREE.BoxGeometry(0.1, 1.5, 0.5); const wing1 = new THREE.Mesh(wingGeo, shipMaterial); const wing2 = wing1.clone(); wing1.position.set(0, -0.75, 1); wing2.position.set(0, -0.75, -1); spaceship.add(wing1, wing2); // Engine const engineGeo = new THREE.CylinderGeometry(0.3, 0.3, 1, 32); const engine = new THREE.Mesh(engineGeo, new THREE.MeshStandardMaterial({ color: 0xff6600 })); engine.position.x = -2.5; engine.rotation.z = Math.PI / 2; spaceship.add(engine); // Controls let moveForward = false, moveBackward = false, moveLeft = false, moveRight = false, moveUp = false, moveDown = false; let pitch = 0, yaw = 0; let canControl = false; let viewMode = "third"; // Pointer Lock renderer.domElement.addEventListener('click', () => { renderer.domElement.requestPointerLock(); }); document.addEventListener('pointerlockchange', () => { canControl = document.pointerLockElement === renderer.domElement; }); document.addEventListener('mousemove', (e) => { if (!canControl) return; yaw -= e.movementX * 0.002; pitch -= e.movementY * 0.002; pitch = Math.max(-Math.PI/2, Math.min(Math.PI/2, pitch)); }); // Keyboard document.addEventListener('keydown', (e) => { switch (e.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; case 'KeyV': viewMode = viewMode === "third" ? "first" : "third"; break; } }); document.addEventListener('keyup', (e) => { switch (e.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; } }); // Space Objects let spaceObjects = []; function createSpaceObject() { const isPlanet = Math.random() < 0.4; const radius = isPlanet ? THREE.MathUtils.randFloat(3, 10) : THREE.MathUtils.randFloat(1, 4); const geometry = new THREE.SphereGeometry(radius, 32, 32); const color = isPlanet ? new THREE.Color(Math.random(), Math.random(), Math.random()) : new THREE.Color(0x888888).offsetHSL(Math.random() * 0.1, 0.2, 0.2); const material = new THREE.MeshStandardMaterial({ color, metalness: isPlanet ? 0.2 : 0.5, roughness: isPlanet ? 0.8 : 0.4 }); const mesh = new THREE.Mesh(geometry, material); return mesh; } function spawnObjectsAround(pos, count = 10, minDist = 100, maxDist = 500) { for (let i = 0; i < count; i++) { const obj = createSpaceObject(); const theta = Math.acos(THREE.MathUtils.randFloatSpread(2)); const phi = THREE.MathUtils.randFloat(0, Math.PI * 2); const dist = THREE.MathUtils.randFloat(minDist, maxDist); obj.position.set( pos.x + dist * Math.sin(theta) * Math.cos(phi), pos.y + dist * Math.sin(theta) * Math.sin(phi), pos.z + dist * Math.cos(theta) ); scene.add(obj); spaceObjects.push(obj); } } spawnObjectsAround(spaceship.position, 30); // Animation Loop function animate() { requestAnimationFrame(animate); // Movement const dir = new THREE.Vector3(); if (moveForward) dir.z -= 1; if (moveBackward) dir.z += 1; if (moveLeft) dir.x -= 1; if (moveRight) dir.x += 1; if (moveUp) dir.y += 1; if (moveDown) dir.y -= 1; dir.normalize(); // Rotation spaceship.rotation.order = 'YXZ'; spaceship.rotation.y = yaw; spaceship.rotation.x = pitch; // Apply movement in local space const speed = 1; const move = dir.clone().applyEuler(spaceship.rotation).multiplyScalar(speed); spaceship.position.add(move); // Camera if (viewMode === "third") { const offset = new THREE.Vector3(0, 3, 10).applyEuler(spaceship.rotation); camera.position.copy(spaceship.position).add(offset); camera.lookAt(spaceship.position); } else { const offset = new THREE.Vector3(0, 0.5, 0).applyEuler(spaceship.rotation); camera.position.copy(spaceship.position).add(offset); const forward = new THREE.Vector3(0, 0, -1).applyEuler(spaceship.rotation); camera.lookAt(camera.position.clone().add(forward)); } // Infinite space spaceObjects = spaceObjects.filter(obj => { if (obj.position.distanceTo(spaceship.position) > 800) { scene.remove(obj); return false; } return true; }); if (spaceObjects.length < 30) { spawnObjectsAround(spaceship.position, 10); } renderer.render(scene, camera); } animate(); // Resize window.addEventListener('resize', () => { camera.aspect = window.innerWidth / window.innerHeight; camera.updateProjectionMatrix(); renderer.setSize(window.innerWidth, window.innerHeight); }); </script> </body> </html>✨ What’s New:
-
🚀 Cool Spaceship:
- Body: Cylinder
- Nose: Cone
- Wings: BoxGeometry
- Engine: Glowing orange cylinder
-
🌌 Realistic Space Objects:
- Planets: Large, colorful, smooth spheres
- Asteroids: Smaller, gray, rougher spheres
- Random sizes and materials
-
🧠 Smarter Object Management:
- Objects are removed when far away
- New ones are spawned around you to simulate infinite space
-
🎮 Controls:
- WASD + Space/Shift for movement
- Mouse to look
- V to toggle first/third person
Let me know if you want to add:
- Real 3D models (GLTF/OBJ)
- Cockpit HUD
- Physics or shooting
- Planet orbits or gravity
Happy flying! 🌠
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.