Skip to content

Commit

Permalink
fixed up physics and bullets and planes and crates
Browse files Browse the repository at this point in the history
  • Loading branch information
RogeredBacon committed Sep 8, 2017
1 parent 3f5e5a5 commit 0d4d8ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const init = () => {
movements.canJump = false;
}
break;
case 17:
case 70:
movements.shooting = true;
break;
}
Expand All @@ -50,7 +50,7 @@ const init = () => {
case 68: // d
movements.right = false;
break;
case 17:
case 70:
movements.shooting = false;
break;
}
Expand Down
4 changes: 3 additions & 1 deletion src/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ const init = () => {

// Cannon init
const world = new CANNON.World();
world.gravity.set(0, -9.82, 0);
world.gravity.set(0, -20, 0);
world.broadphase = new CANNON.NaiveBroadphase();
world.solver.iterations = 10;
world.solver = new CANNON.SplitSolver(new CANNON.GSSolver());
// shape is shape of geometry/wireframe
const shape = new CANNON.Box(new CANNON.Vec3(10, 10, 10));
// body is it being effected by forces.
Expand All @@ -45,6 +46,7 @@ const init = () => {
world.addBody(body);

const groundShape = new CANNON.Plane();
groundShape.collisionResponse = true;
const groundBody = new CANNON.Body({ mass: 0 });
groundBody.addShape(groundShape);
groundBody.position.set(0, -14, 0);
Expand Down
12 changes: 8 additions & 4 deletions src/letsMove.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = function (
if (bullets[index].alive == false) {
cannonBullets.splice(index, 1);
bullets.splice(index, 1);
world.remove(cannonBullets[index]);
continue;
}
// bullets[index].position.add(bullets[index].velocity);
Expand All @@ -54,14 +55,15 @@ module.exports = function (
if (movements.shooting) {
// shoot.bullet(scene);
const bullet = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 8, 8),
new THREE.SphereGeometry(1.3, 8, 8),
new THREE.MeshBasicMaterial(),
);

const shape = new CANNON.Sphere(new CANNON.Vec3(0.5));
const shape = new CANNON.Sphere(new CANNON.Vec3(1.3));
const body = new CANNON.Body({
mass: 1,
mass: 5,
});
body.linearDamping = 0;
body.addShape(shape);
body.position.set(
raycaster.ray.origin.x,
Expand All @@ -87,12 +89,14 @@ module.exports = function (
setTimeout(() => {
bullet.alive = false;
scene.remove(bullet);
world.remove(world.bodies[world.bodies.length - 1]);
}, 3000);
cannonBullets.push(world.bodies[world.bodies.length - 1]);
bullets.push(bullet);
scene.add(bullet);
cannonBullets[cannonBullets.length - 1].velocity = bullet.velocity;
cannonBullets[cannonBullets.length - 1].velocity.x *= 150;
cannonBullets[cannonBullets.length - 1].velocity.y += 10;
cannonBullets[cannonBullets.length - 1].velocity.z *= 150;
}

if (movements.forward) { velocity.z -= 2000.0 * delta; }
Expand Down

0 comments on commit 0d4d8ca

Please sign in to comment.