51 lines
No EOL
1.5 KiB
JavaScript
51 lines
No EOL
1.5 KiB
JavaScript
(function() {
|
|
|
|
// Script.include("utils.js");
|
|
|
|
var _this;
|
|
|
|
var RANGE = 5.0;
|
|
var AUDIO_RANGE = 0.5 * RANGE;
|
|
var cameraAxis = Quat.getFront(Camera.getOrientation());
|
|
var audioPosition = Vec3.sum(Camera.getPosition(), Vec3.multiply(AUDIO_RANGE, cameraAxis));
|
|
var audioOptions = { volume: 0.9, position: audioPosition };
|
|
|
|
function playAudio(clip) {
|
|
var soundInjector = Audio.playSound(clip, audioOptions);
|
|
}
|
|
|
|
Spring = function() {
|
|
_this = this;
|
|
}
|
|
|
|
Spring.prototype = {
|
|
entityID: null,
|
|
sound: null,
|
|
injector: null,
|
|
|
|
preload: function(entityID) { // multiple actions?
|
|
_this.entityID = entityID;
|
|
|
|
// var SOUND_URL = "https://hifi-content.s3.amazonaws.com/lincoln/sounds/BDRM07.wav";// right
|
|
var SOUND_URL = "https://hifi-content.s3.amazonaws.com/lincoln/sounds/" + Entities.getEntityProperties(entityID).name + ".wav";
|
|
_this.hitSound = SoundCache.getSound(SOUND_URL);
|
|
|
|
// persisting?
|
|
Entities.addAction("spring", _this.entityID, {
|
|
targetPosition: Entities.getEntityProperties(_this.entityID).position,
|
|
targetRotation: Entities.getEntityProperties(_this.entityID).rotation,
|
|
angularTimeScale: 0.01,
|
|
linearTimeScale: 0.001
|
|
})
|
|
},
|
|
clickReleaseOnEntity: function(entityID, mouseEvent){
|
|
print("clicked..");
|
|
Script.setTimeout(function() { playAudio(_this.hitSound); }, 10)
|
|
},
|
|
collisionWithEntity: function(me, otherEntity,collision){
|
|
Script.setTimeout(function() { playAudio(_this.hitSound); }, 10)
|
|
}
|
|
}
|
|
|
|
return new Spring();
|
|
}) |