diff --git a/src/animate.js b/src/animate.js index c5d7d8b..4eea67c 100644 --- a/src/animate.js +++ b/src/animate.js @@ -19,6 +19,7 @@ const start = (options) => { timeStep, health, gun, + guntime, // objload, } = options; @@ -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(); diff --git a/src/getBullet.js b/src/getBullet.js index ea599c3..3b41b2d 100644 --- a/src/getBullet.js +++ b/src/getBullet.js @@ -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() { @@ -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; diff --git a/src/letsMove.js b/src/letsMove.js index e1a30e7..aec4c97 100644 --- a/src/letsMove.js +++ b/src/letsMove.js @@ -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; @@ -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; @@ -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) => { @@ -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, );