Skip to content

Commit

Permalink
Changed the bullets to follow the gun exactly(as it moves up and down…
Browse files Browse the repository at this point in the history
… idly) and to shoot out of the end

#4
#2
  • Loading branch information
RogeredBacon committed Sep 13, 2017
1 parent 1757b71 commit 849c296
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const start = (options) => {
timeStep,
health,
gun,
guntime,
// objload,
} = options;

Expand All @@ -40,7 +41,7 @@ const start = (options) => {
socket.emitPlayerPosition(player.position, player.rotation);

if (movements.shooting) {
const bullet = getBullet();
const bullet = getBullet(gun, guntime);
socket.emitBulletPosition(bullet.randomid, bullet.velocity, bullet.position);
}
const players = otherPlayers.get();
Expand Down
18 changes: 7 additions & 11 deletions src/getBullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
const THREE = require('three');
const pointLockers = require('./pointLockers');
const getScene = require('./getScene');
// const shoot = require('./shoot.js');
const letsMove = require('./letsMove');

const { movements } = require('./controls');
const getRaycaster = require('./getRaycaster');


const velocity = new THREE.Vector3();

function guid() {
Expand All @@ -21,27 +20,24 @@ function guid() {
s4()}-${s4()}${s4()}${s4()}`;
}

const getBullet = () => {
const getBullet = (gun, guntime) => {
const bullet = new THREE.Mesh(
new THREE.SphereGeometry(1, 8, 8),
new THREE.MeshBasicMaterial(),
);

const scene = getScene();

const raycaster = getRaycaster();
bullet.position.set(
raycaster.ray.origin.x,
raycaster.ray.origin.y,
raycaster.ray.origin.z,
pointLockers().position.x - Math.sin((pointLockers().rotation._y) - 0.5) * 6,
(gun.position.y - 5) - 0.5 + Math.sin(guntime * 4 + (pointLockers().position.x + pointLockers().position.y) * 0.1) * 0.03,
pointLockers().position.z - Math.cos((pointLockers().rotation._y) - 0.5) * 6,
);

const player = pointLockers();

bullet.velocity = new THREE.Vector3(
-Math.sin(player.rotation._y - 0.2) * 20,
-Math.sin(pointLockers().rotation._y) * 20,
0,
-Math.cos(player.rotation._y - 0.2) * 20,
-Math.cos(pointLockers().rotation._y) * 20,
);

bullet.alive = true;
Expand Down
20 changes: 12 additions & 8 deletions src/letsMove.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const getBullet = require('./getBullet');
const { movements } = require('./controls');

const bullets = [];
let clock = {};
const velocity = new THREE.Vector3();
let lastHealthPickup = 0;
let life = 30;
Expand Down Expand Up @@ -39,6 +40,9 @@ module.exports = function (
// health.rotation.x += 0.004;
health.rotation.y += 0.008;

clock = new THREE.Clock();
const guntime = Date.now() * 0.0005;
const gundelta = clock.getDelta();

if (!document.getElementById('health').textContent) {
document.getElementById('health').textContent = life;
Expand Down Expand Up @@ -85,13 +89,6 @@ module.exports = function (
bullets[index].position.add(bullets[index].velocity);
}

if (movements.shooting) {
const bullet = getBullet();
bullets.push(bullet);
scene.add(bullet);
movements.canShoot = 50;
}

if (movements.canShoot > 0) movements.canShoot -= 1;

Object.keys(otherBullets.get()).forEach((id) => {
Expand Down Expand Up @@ -143,10 +140,17 @@ module.exports = function (
pointLockers().position.y = 10;
movements.canJump = true;
}

if (movements.shooting) {
const bullet = getBullet(gun, guntime);
bullets.push(bullet);
scene.add(bullet);
movements.canShoot = 50;
}
// Player Weapon
gun.position.set(
pointLockers().position.x - Math.sin((pointLockers().rotation._y) - 0.5) * 0.6,
pointLockers().position.y - 0.5,
pointLockers().position.y - 0.5 + Math.sin(guntime * 4 + (pointLockers().position.x + pointLockers().position.y) * 0.1) * 0.03,
pointLockers().position.z - Math.cos((pointLockers().rotation._y) - 0.5) * 0.6,
);

Expand Down

0 comments on commit 849c296

Please sign in to comment.