From 7fb906dbc69d3756d7eab14a9c255a81262c3e4e Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 21 Mar 2021 02:42:27 +0000 Subject: [PATCH] Add randomness to lasers --- webclient/src/spaceport/Laser.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webclient/src/spaceport/Laser.js b/webclient/src/spaceport/Laser.js index e4f2690..c38aad0 100644 --- a/webclient/src/spaceport/Laser.js +++ b/webclient/src/spaceport/Laser.js @@ -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)) {