shootable

This commit is contained in:
Eric Levin 2015-11-13 11:15:44 -08:00
parent 281d058a24
commit 6f994d6274
2 changed files with 19 additions and 19 deletions

View file

@ -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,

View file

@ -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() {