Add randomness to lasers

This commit is contained in:
Tanner Collin 2021-03-21 02:42:27 +00:00
parent 3529916726
commit 7fb906dbc6

View File

@ -1,6 +1,7 @@
import * as THREE from 'three';
const LASER_SIZE = 0.5;
const BULLET_SPREAD = 0.1;
export class Laser {
constructor(ship) {
@ -8,6 +9,9 @@ export class Laser {
this.direction = ship.direction;
this.kill = false;
this.stepX = (Math.random()-0.5) * BULLET_SPREAD;
this.stepY = (Math.random()-0.5) * BULLET_SPREAD;
ship.mesh.getWorldPosition(position)
const shipGeo = new THREE.BoxGeometry(
@ -28,6 +32,8 @@ export class Laser {
}
update({ deltaTime }) {
this.mesh.position.x += this.stepX;
this.mesh.position.y += this.stepY;
this.mesh.position.z += 0.5 * this.direction;
if (Math.abs(this.mesh.position.z > 475/2)) {