mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 00:34:22 +02:00
fire code and sound code
This commit is contained in:
parent
f3d602a6f3
commit
6129d3757e
4 changed files with 156 additions and 28 deletions
|
@ -15,6 +15,7 @@
|
|||
Script.include("../../libraries/utils.js");
|
||||
|
||||
var NOTCH_DETECTOR_SEARCH_RADIUS = 0.25;
|
||||
var FIRE_DETECTOR_SEARCH_RADIUS = 0.25;
|
||||
|
||||
var _this;
|
||||
|
||||
|
@ -26,18 +27,23 @@
|
|||
Arrow.prototype = {
|
||||
stickOnCollision: false,
|
||||
notched: false,
|
||||
burning: false,
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
|
||||
},
|
||||
|
||||
unload: function() {},
|
||||
unload: function() {
|
||||
|
||||
},
|
||||
|
||||
continueNearGrab: function() {
|
||||
this.currentProperties = Entities.getEntityProperties(this.entityID, "position");
|
||||
if (this.isBurning === true) {
|
||||
updateFirePosition();
|
||||
}
|
||||
if (this.notched !== true) {
|
||||
this.searchForNotchDetectors();
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -59,6 +65,93 @@
|
|||
}
|
||||
|
||||
},
|
||||
searchForFires: function() {
|
||||
if (this.notched === true) {
|
||||
return
|
||||
};
|
||||
|
||||
var ids = Entities.findEntities(this.currentProperties.position, FIRE_DETECTOR_SEARCH_RADIUS);
|
||||
var i, properties;
|
||||
for (i = 0; i < ids.length; i++) {
|
||||
id = ids[i];
|
||||
properties = Entities.getEntityProperties(id, 'name');
|
||||
if (properties.name == "Hifi-Arrow-Fire-Source") {
|
||||
print('NEAR A FIRE SOURCE!!!')
|
||||
this.burning = true;
|
||||
this.fire = this.createFireParticleSystem();
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
updateFirePosition: function() {
|
||||
Entities.editEntity(this.fire, {
|
||||
position: this.currentProperties.position
|
||||
})
|
||||
},
|
||||
createFireParticleSystem: function() {
|
||||
var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0);
|
||||
|
||||
var animationSettings = JSON.stringify({
|
||||
fps: 30,
|
||||
running: true,
|
||||
loop: true,
|
||||
firstFrame: 1,
|
||||
lastFrame: 10000
|
||||
});
|
||||
|
||||
var fire = Entities.addEntity({
|
||||
type: "ParticleEffect",
|
||||
name: "Hifi-Arrow-Fire-Source",
|
||||
animationSettings: animationSettings,
|
||||
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
|
||||
emitRate: 100,
|
||||
position: this.bowProperties.position,
|
||||
colorStart: {
|
||||
red: 70,
|
||||
green: 70,
|
||||
blue: 137
|
||||
},
|
||||
color: {
|
||||
red: 200,
|
||||
green: 99,
|
||||
blue: 42
|
||||
},
|
||||
colorFinish: {
|
||||
red: 255,
|
||||
green: 99,
|
||||
blue: 32
|
||||
},
|
||||
radiusSpread: 0.01,
|
||||
radiusStart: 0.02,
|
||||
radiusEnd: 0.001,
|
||||
particleRadius: 0.5,
|
||||
radiusFinish: 0.0,
|
||||
emitOrientation: myOrientation,
|
||||
emitSpeed: 0.3,
|
||||
speedSpread: 0.1,
|
||||
alphaStart: 0.05,
|
||||
alpha: 0.1,
|
||||
alphaFinish: 0.05,
|
||||
emitDimensions: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 0.1
|
||||
},
|
||||
polarFinish: 0.1,
|
||||
emitAcceleration: {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0
|
||||
},
|
||||
accelerationSpread: {
|
||||
x: 0.1,
|
||||
y: 0.01,
|
||||
z: 0.1
|
||||
},
|
||||
lifespan: 1
|
||||
});
|
||||
return fire
|
||||
},
|
||||
getBowID: function(notchDetectorID) {
|
||||
var properties = Entities.getEntityProperties(notchDetectorID, "userData");
|
||||
var userData = JSON.parse(properties.userData);
|
||||
|
@ -95,6 +188,7 @@
|
|||
|
||||
setEntityCustomData('hifiBowKey', bowID, {
|
||||
hasArrowNotched: true,
|
||||
arrowIsBurning: this.isBurning,
|
||||
arrowID: this.entityID
|
||||
});
|
||||
|
||||
|
@ -122,16 +216,13 @@
|
|||
// // })
|
||||
// // }
|
||||
|
||||
// },
|
||||
playCollisionSound: function() {
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
function deleteEntity(entityID) {
|
||||
if (entityID === this.entityID) {
|
||||
if (entityID === _this.entityID) {
|
||||
if (_this.isBurning === true) {
|
||||
_this.deleteEntity(_this.fire);
|
||||
Entities.deleteEntity(_this.fire);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,6 +177,7 @@
|
|||
this.hasArrowNotched = userData.hifiBowKey.hasArrowNotched;
|
||||
|
||||
this.arrow = userData.hifiBowKey.arrowID;
|
||||
this.arrowIsBurning = userData.hifiBowKey.isBurning;
|
||||
|
||||
setEntityCustomData('grabbableKey', this.entityID, {
|
||||
turnOffOtherHand: true,
|
||||
|
@ -432,7 +433,6 @@
|
|||
this.stringDrawn = true;
|
||||
this.createStrings();
|
||||
var arrowTracker = this.createArrowTracker(this.arrow);
|
||||
print('ARROW TRACKER IS:::' + JSON.stringify(arrowTracker));
|
||||
this.arrowTrackers.push(arrowTracker)
|
||||
this.stringData.handPosition = this.getStringHandPosition();
|
||||
this.stringData.handRotation = this.getStringHandRotation();
|
||||
|
@ -456,8 +456,6 @@
|
|||
|
||||
updateArrowPositionInNotch: function() {
|
||||
//move it backwards
|
||||
|
||||
|
||||
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
|
||||
var pullBackDistance = Vec3.length(handToNotch);
|
||||
|
||||
|
@ -468,6 +466,7 @@
|
|||
var pullBackOffset = Vec3.multiply(handToNotch, -pullBackDistance);
|
||||
var arrowPosition = Vec3.sum(this.notchDetectorPosition, pullBackOffset);
|
||||
|
||||
//move it forward a bit
|
||||
var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET);
|
||||
var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset);
|
||||
|
||||
|
@ -481,7 +480,6 @@
|
|||
},
|
||||
|
||||
releaseArrow: function() {
|
||||
|
||||
print('RELEASE ARROW!!!')
|
||||
|
||||
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
|
||||
|
@ -490,7 +488,6 @@
|
|||
pullBackDistance = 0.6;
|
||||
}
|
||||
|
||||
|
||||
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
|
||||
|
||||
print('HAND DISTANCE:: ' + pullBackDistance);
|
||||
|
@ -503,7 +500,6 @@
|
|||
velocity: forwardVec
|
||||
};
|
||||
|
||||
|
||||
Entities.editEntity(this.arrow, arrowProperties);
|
||||
|
||||
setEntityCustomData('hifiBowKey', this.entityID, {
|
||||
|
@ -637,7 +633,7 @@
|
|||
animationSettings: animationSettings,
|
||||
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
|
||||
emitRate: 100,
|
||||
position: MyAvatar.position,
|
||||
position: this.bowProperties.position,
|
||||
colorStart: {
|
||||
red: 70,
|
||||
green: 70,
|
||||
|
@ -656,7 +652,7 @@
|
|||
radiusSpread: 0.01,
|
||||
radiusStart: 0.02,
|
||||
radiusEnd: 0.001,
|
||||
particleRadius: 0.05,
|
||||
particleRadius: 0.5,
|
||||
radiusFinish: 0.0,
|
||||
emitOrientation: myOrientation,
|
||||
emitSpeed: 0.3,
|
||||
|
@ -689,6 +685,9 @@
|
|||
createArrowTracker: function(arrow, isBurning) {
|
||||
print('in create arrow tracker:::' + arrow)
|
||||
var _t = this;
|
||||
|
||||
var isBurning = this.arrowIsBurning;
|
||||
//delete this line below once debugging is done
|
||||
var isBurning = isBurning || true;
|
||||
var arrowTracker = {
|
||||
arrowID: arrow,
|
||||
|
@ -728,15 +727,26 @@
|
|||
this.childEntities.push(this.fireParticleSystem);
|
||||
},
|
||||
updateChildEntities: function(arrowID) {
|
||||
// print('ARROWID??'+arrowID)
|
||||
// print('UPDATING CHILDREN OF TRACKER:::' + this.childEntities.length+" ARROW::"+arrowID);
|
||||
|
||||
print('UPDATING CHILDREN OF TRACKER:::' + this.childEntities.length);
|
||||
var arrowProperties = Entities.getEntityProperties(this.arrowID, ["position", "rotation"]);
|
||||
|
||||
//update the positions
|
||||
this.soundEntities.forEach(function(injector) {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
position: arrowProperties.position
|
||||
};
|
||||
injector.options = audioProperties;
|
||||
})
|
||||
|
||||
this.childEntities.forEach(function(child) {
|
||||
Entities.editEntity(child, {
|
||||
position: arrowProperties.position,
|
||||
rotation: arrowProperties.rotation
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
};
|
||||
arrowTracker.init();
|
||||
|
@ -746,12 +756,25 @@
|
|||
return arrowTracker
|
||||
},
|
||||
createWhizzingSound: function() {
|
||||
var sound;
|
||||
return sound
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
position: this.bowProperties.position,
|
||||
loop: true
|
||||
};
|
||||
var injector = Audio.playSound(this.shootArrowSound, audioProperties);
|
||||
|
||||
return injector
|
||||
},
|
||||
createFireSound: function() {
|
||||
var sound;
|
||||
return sound
|
||||
createFireBurningSound: function() {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
position: this.bowProperties.position,
|
||||
loop: true
|
||||
};
|
||||
|
||||
var injector = Audio.playSound(this.fireBurningSound, audioProperties);
|
||||
|
||||
return injector
|
||||
},
|
||||
createGlowBoxAsModel: function() {
|
||||
var modelURL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/glowBox.fbx';
|
||||
|
@ -810,7 +833,6 @@
|
|||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
var glowBox = Entities.addEntity(properties);
|
||||
return glowBox
|
||||
},
|
||||
|
@ -822,7 +844,22 @@
|
|||
// print('TRACKER ARROW ID'+tracker.arrowID)
|
||||
tracker.updateChildEntities(arrowID);
|
||||
})
|
||||
}
|
||||
},
|
||||
playStringPullSound: function() {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
this.stringPullInjector = Audio.playSound(this.stringPullSound, audioProperties);
|
||||
},
|
||||
playShootArrowSound: function(sound) {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
Audio.playSound(this.shootArrowSound, audioProperties);
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ var arrow;
|
|||
function createArrow(i) {
|
||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
y: 0.5,
|
||||
z: 0
|
||||
}), Vec3.multiply(1.25*i, Quat.getFront(Camera.getOrientation())));
|
||||
|
||||
|
@ -63,7 +63,7 @@ function createArrow(i) {
|
|||
}
|
||||
|
||||
var i;
|
||||
for(i=1;i<4;i++){
|
||||
for(i=1;i<6;i++){
|
||||
createArrow(i);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ var BOW_GRAVITY = {
|
|||
|
||||
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
y: 0.5,
|
||||
z: 0
|
||||
}), Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
|
||||
|
||||
|
|
Loading…
Reference in a new issue