Yea i took a break of coding and then i got ERRORS…
Just take a look at my Script:
https://is.gd/e6GGpy
Here
The error that I see when I press the arrow keys is:
VM59 code.html:85 Uncaught ReferenceError: launcher is not defined
at HTMLDocument.sendKeyDown (VM59 code.html:85)
That error says that the code is trying to do something with the launcher
variable, but the launcher
variable is not defined.
If you look earlier in the code, you can find:
var Launcher = new Launcher();
That defines a Launcher
variable, not the launcher
(lowercase) variable that the code is trying to use. If you switch to lowercase, the code should work.
-Chris
Idk what you mean…
Can you send me the Url for the fixed Code, what do you mean with “Lowercase”-“UpperCase”?
Change this line:
var Launcher = new Launcher();
To this:
var launcher = new Launcher();
Nah, idk but its still not working.
Maybe can you send me your ENTIRE code, so i can replace my old code to the new one.
The code in 3DE: https://is.gd/JzIOuS
The full code:
<body></body>
<script src="/three.js"></script>
<script src="/physi.js"></script>
<script scr="/scoreboard.js"></script>
<script>
// Physics settings
Physijs.scripts.ammo = '/ammo.js';
Physijs.scripts.worker = '/physijs_worker.js';
// The "scene" is where stuff in our game will happen:
var scene = new Physijs.Scene();
scene.setGravity(new THREE.Vector3( 0, -100, 0 ));
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;
camera.position.y = 200;
camera.lookAt(new THREE.Vector3(0,0,0));
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 ********
function Launcher() {
this.angle = 0;
this.power = 0;
this.draw();
}
Launcher.prototype.draw = function() {
var direction = new THREE.Vector3(0, 1, 0);
var position = new THREE.Vector3(0, -100, 250);
var length = 100;
this.arrow = new THREE.ArrowHelper(
direction,
position,
length,
'yellow'
);
scene.add(this.arrow);
};
Launcher.prototype.vector = function() {
return new THREE.Vector3(
Math.sin(this.angle),
Math.cos(this.angle),
0
);
};
Launcher.prototype.moveLeft = function(){
this.angle = this.angle - Math.PI / 100;
this.arrow.setDirection(this.vector());
};
var launcher = new Launcher();
// Animate motion in the game
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
// Run physics
function gameStep() {
scene.simulate();
// Update physics 60 times a second so that motion is smooth
setTimeout(gameStep, 1000/60);
}
gameStep();
document.addEventListener('keydown', sendKeyDown);
function sendKeyDown(event) {
var code = event.code;
if (code == 'ArrowLeft') launcher.moveLeft();
}
</script>
Thanks!, now its working