Add randomness to lasers
This commit is contained in:
parent
3529916726
commit
7fb906dbc6
|
@ -1,6 +1,7 @@
|
||||||
import * as THREE from 'three';
|
import * as THREE from 'three';
|
||||||
|
|
||||||
const LASER_SIZE = 0.5;
|
const LASER_SIZE = 0.5;
|
||||||
|
const BULLET_SPREAD = 0.1;
|
||||||
|
|
||||||
export class Laser {
|
export class Laser {
|
||||||
constructor(ship) {
|
constructor(ship) {
|
||||||
|
@ -8,6 +9,9 @@ export class Laser {
|
||||||
this.direction = ship.direction;
|
this.direction = ship.direction;
|
||||||
this.kill = false;
|
this.kill = false;
|
||||||
|
|
||||||
|
this.stepX = (Math.random()-0.5) * BULLET_SPREAD;
|
||||||
|
this.stepY = (Math.random()-0.5) * BULLET_SPREAD;
|
||||||
|
|
||||||
ship.mesh.getWorldPosition(position)
|
ship.mesh.getWorldPosition(position)
|
||||||
|
|
||||||
const shipGeo = new THREE.BoxGeometry(
|
const shipGeo = new THREE.BoxGeometry(
|
||||||
|
@ -28,6 +32,8 @@ export class Laser {
|
||||||
}
|
}
|
||||||
|
|
||||||
update({ deltaTime }) {
|
update({ deltaTime }) {
|
||||||
|
this.mesh.position.x += this.stepX;
|
||||||
|
this.mesh.position.y += this.stepY;
|
||||||
this.mesh.position.z += 0.5 * this.direction;
|
this.mesh.position.z += 0.5 * this.direction;
|
||||||
|
|
||||||
if (Math.abs(this.mesh.position.z > 475/2)) {
|
if (Math.abs(this.mesh.position.z > 475/2)) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user