From 22efcb1854ae45c2f937687f0db0ae370475ca98 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 30 Nov 2015 11:42:34 -0800 Subject: [PATCH] Added sounds to pistol --- examples/weapons/pistol/pistol.js | 13 ++++++++++++- examples/weapons/pistol/pistolSpawner.js | 1 + unpublishedScripts/hiddenEntityReset.js | 1 + unpublishedScripts/masterReset.js | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/weapons/pistol/pistol.js b/examples/weapons/pistol/pistol.js index 834f021d42..1cd06dc436 100644 --- a/examples/weapons/pistol/pistol.js +++ b/examples/weapons/pistol/pistol.js @@ -34,6 +34,8 @@ z: 0.16 } this.fireSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/GUN-SHOT2.raw"); + this.ricochetSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/Ricochet.L.wav"); + this.playRichochetSoundChance = 0.7; this.fireVolume = 0.5; this.bulletForce = 10; @@ -67,7 +69,7 @@ }); } else if (this.triggerValue >= DISABLE_LASER_THRESHOLD && this.showLaser === false) { this.showLaser = true - Overlays.editOverlay(this.laser, { + Overlays.editOverlay(this.laser, { visible: true }); } @@ -126,10 +128,19 @@ position: this.barrelPoint, volume: this.fireVolume }); + this.createGunFireEffect(this.barrelPoint) var intersection = Entities.findRayIntersectionBlocking(pickRay, true); if (intersection.intersects) { this.createEntityHitEffect(intersection.intersection); + if (Math.random() < this.playRichochetSoundChance) { + Script.setTimeout(function() { + Audio.playSound(_this.ricochetSound, { + position: intersection.intersection, + volume: _this.fireVolume + }); + }, randFloat(10, 200)); + } if (intersection.properties.collisionsWillMove === 1) { // Any entity with collisions will move can be shot Entities.editEntity(intersection.entityID, { diff --git a/examples/weapons/pistol/pistolSpawner.js b/examples/weapons/pistol/pistolSpawner.js index 4569233796..9b677faa53 100644 --- a/examples/weapons/pistol/pistolSpawner.js +++ b/examples/weapons/pistol/pistolSpawner.js @@ -20,6 +20,7 @@ var pistol = Entities.addEntity({ }, shapeType: 'box', collisionsWillMove: true, + collisionSoundURL: "https://s3.amazonaws.com/hifi-public/sounds/Guns/Gun_Drop_and_Metalli_1.wav", userData: JSON.stringify({ grabbableKey: { spatialKey: { diff --git a/unpublishedScripts/hiddenEntityReset.js b/unpublishedScripts/hiddenEntityReset.js index 94f34532e6..e7d8fb76d3 100644 --- a/unpublishedScripts/hiddenEntityReset.js +++ b/unpublishedScripts/hiddenEntityReset.js @@ -164,6 +164,7 @@ name: "pistol", modelURL: modelURL, position: position, + collisionSoundURL: "https://s3.amazonaws.com/hifi-public/sounds/Guns/Gun_Drop_and_Metalli_1.wav", dimensions: { x: 0.05, y: .23, diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 9d740328b2..e4460375e0 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -155,6 +155,7 @@ MasterReset = function() { shapeType: 'box', gravity: {x: 0, y: -3.0, z: 0}, collisionsWillMove: true, + collisionSoundURL: "https://s3.amazonaws.com/hifi-public/sounds/Guns/Gun_Drop_and_Metalli_1.wav", userData: JSON.stringify({ grabbableKey: { spatialKey: {