diff --git a/examples/weapons/pistol.js b/examples/weapons/pistol.js index 8e8dfd6be1..7fb620550d 100644 --- a/examples/weapons/pistol.js +++ b/examples/weapons/pistol.js @@ -25,6 +25,7 @@ HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; var fireSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/GUN-SHOT2.raw"); var LASER_WIDTH = 2; +var GUN_FORCE = 10; var POSE_CONTROLS = [Controller.Standard.LeftHand, Controller.Standard.RightHand]; var TRIGGER_CONTROLS = [Controller.Standard.LT, Controller.Standard.RT]; var MIN_THROWER_DELAY = 1000; @@ -61,6 +62,8 @@ var barrelVectors = [0, 0]; var barrelTips = [0, 0]; var pointer = []; +var shootAnything = false; + pointer.push(Overlays.addOverlay("line3d", { start: ZERO_VECTOR, end: ZERO_VECTOR, @@ -124,9 +127,11 @@ function triggerChanged(side, value) { position: barrelTips[side], volume: 1.0 }); + + var shotDirection = Vec3.normalize(barrelVectors[side]); var pickRay = { origin: barrelTips[side], - direction: Vec3.normalize(barrelVectors[side]) + direction: shotDirection }; createMuzzleFlash(barrelTips[side]); var intersection = Entities.findRayIntersection(pickRay, true); @@ -134,11 +139,16 @@ function triggerChanged(side, value) { if (intersection.properties.name === "rat") { print("HOLY SHIT YOU JUST HIT A RAT!"); var forceDirection = JSON.stringify({ - forceDirection: barrelVectors[side] + 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); } diff --git a/examples/weapons/ratSpawner.js b/examples/weapons/ratSpawner.js index 9390604daf..f49f7ac4b9 100644 --- a/examples/weapons/ratSpawner.js +++ b/examples/weapons/ratSpawner.js @@ -1,10 +1,15 @@ var scriptURL = Script.resolvePath('rat.js'); +var naturalDimensions = {x: 11.31, y: 3.18, z: 2.19}; +var sizeScale = 0.1; +var dimensions = Vec3.multiply(naturalDimensions, sizeScale); var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); var rat = Entities.addEntity({ - type: "Box", + type: "Model", + modelURL: "https://hifi-public.s3.amazonaws.com/ryan/rat.fbx", name: 'rat', position: center, - dimensions: {x: 0.4, y: 0.4, z: 0.4}, + dimensions: dimensions, + shapeType: 'box', color: {red: 200, green: 20, blue: 200}, gravity: {x: 0, y: -9.8, z: 0}, collisionsWillMove: true,