From 6f994d6274888417b96b70174344a1b01abfd87f Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Fri, 13 Nov 2015 11:15:44 -0800 Subject: [PATCH] shootable --- examples/weapons/pistol.js | 35 +++++++++++++++++----------------- examples/weapons/ratSpawner.js | 3 ++- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/examples/weapons/pistol.js b/examples/weapons/pistol.js index 42e3d033bb..6c329fdbba 100644 --- a/examples/weapons/pistol.js +++ b/examples/weapons/pistol.js @@ -76,6 +76,7 @@ var barrelVectors = [0, 0]; var barrelTips = [0, 0]; +// If enabled, anything can be shot, otherwise, an entity needs to have "isShootable" set in its userData var shootAnything = true; @@ -106,7 +107,6 @@ function update(deltaTime) { alpha: 1, }); - } } @@ -139,7 +139,7 @@ var kickback = function(animationProperties) { function fire(side, value) { - if(value == 0) { + if (value == 0) { return; } Audio.playSound(fireSound, { @@ -156,24 +156,23 @@ function fire(side, value) { var intersection = Entities.findRayIntersection(pickRay, true); if (intersection.intersects) { - if (intersection.properties.name === "rat") { - var forceDirection = JSON.stringify({ - forceDirection: shotDirection - }); - Entities.callEntityMethod(intersection.entityID, 'onHit', [forceDirection]); - } else { - Script.setTimeout(function() { - if (shootAnything) { - Entities.editEntity(intersection.entityID, { - velocity: Vec3.multiply(shotDirection, GUN_FORCE) - }); - } - createWallHit(intersection.intersection); - }, 50); - } + + Script.setTimeout(function() { + if (shootAnything && intersection.properties.collisionsWillMove === true) { + // Any entity with collisions will move can be shot + Entities.editEntity(intersection.entityID, { + velocity: Vec3.multiply(shotDirection, GUN_FORCE) + }); + createEntityHitEffect(intersection.intersection); + } else { + + } + }, 50); + } } +function function scriptEnding() { @@ -209,7 +208,7 @@ Script.scriptEnding.connect(scriptEnding); Script.update.connect(update); -function createWallHit(position) { +function createEntityHitEffect(position) { var flash = Entities.addEntity({ type: "ParticleEffect", position: position, diff --git a/examples/weapons/ratSpawner.js b/examples/weapons/ratSpawner.js index f49f7ac4b9..28fe5e8b8a 100644 --- a/examples/weapons/ratSpawner.js +++ b/examples/weapons/ratSpawner.js @@ -13,7 +13,8 @@ var rat = Entities.addEntity({ color: {red: 200, green: 20, blue: 200}, gravity: {x: 0, y: -9.8, z: 0}, collisionsWillMove: true, - script: scriptURL + script: scriptURL, + userData: JSON.stringify({isShootable: true}); }); function cleanup() {