Explain how your code is misbehaving:
Hello, i am from Germany and I have a question!
I am in chapter 5 (Bonus 2) and I wanna add a plane, but If it type the code in the 3rd line to add the plane this message comes:
This is all my code but idk why it stands there
// Paste your code here, this is all my code…
// The "scene" is where stuff in our game will happen: var scene = new THREE.Scene(); var flat = {flatShading: true}; var light = new THREE.AmbientLight('white', 0.8); scene.add(light);// The “camera” is what sees the stuff:
var aspectRatio = window.innerWidth / window.innerHeight;
var camera = new THREE.PerspectiveCamera(75, aspectRatio, 1, 10000);
camera.position.z = 500;
scene.add(camera);
// The “renderer” draws what the camera sees onto the screen:
var renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// ******** START CODING ON THE NEXT LINE ********
var shape = new THREE.SphereGeometry(50);
var cover = new THREE.MeshBasicMaterial({color: ‘blue’});
var planet = new THREE.Mesh(shape, cover);
planet.position.set(-300, 0, 0);
scene.add(planet);
var shape = new THREE.SphereGeometry(50);
var cover = new THREE.MeshBasicMaterial({color: ‘yellow’});
var planet = new THREE.Mesh(shape, cover);
planet.position.set(200, 0, 250);
scene.add(planet);
function makePlanet() {
var size = r(50);
var x = r(1000) - 500;
var y = r(1000) - 500;
var z = r(1000) - 1000;
var surface = rColor();
var shape = new THREE.SphereGeometry(size);
var cover = new THREE.MeshBasicMaterial({color: surface});
var planet = new THREE.Mesh(shape, cover);
planet.position.set(x, y, z);
scene.add(planet);
}
makePlanet();
makePlanet();
for (var i=0; i<100; i++) {
makePlanet();
}
console.log(Math.random());
function r(max) {
if (max) return max * Math.random();
return Math.random();
}
var randomNum = r();
console.log(randomNum);
randomNum = r(100);
console.log(randomNum);
console.log(r(100));
console.log(r(100));
function rColor() {
return new THREE.Color(r(), r(), r());
}
var controls = new THREE.FlyControls(camera);
controls.movementSpeed = 100;
controls.rollSpeed = 0.5;
controls.dragToLook = true;
controls.autoForward = false;
var clock = new THREE.Clock();
function animate() {
var delta = clock.getDelta();
controls.update(delta);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// Now, show what the camera sees on the screen:
renderer.render(scene, camera);
Include any more information that you like here…
I have the german book, but I hope nothing is that huge of a different!
Have a nice day