This commit is contained in:
James B. Pollack 2015-11-13 10:30:17 -08:00
parent ff2b5fc8da
commit f3d602a6f3
3 changed files with 36 additions and 16 deletions

View file

@ -619,7 +619,8 @@
}, },
createFireParticleSystem: function() { createFireParticleSystem: function() {
//will probably need to dynamically update the orientation to match the arrow??? print('MAKING A FIRE')
//will probably need to dynamically update the orientation to match the arrow???
var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0); var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0);
var animationSettings = JSON.stringify({ var animationSettings = JSON.stringify({
@ -635,8 +636,8 @@
name: "Hifi-Arrow-Fire", name: "Hifi-Arrow-Fire",
animationSettings: animationSettings, animationSettings: animationSettings,
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
position: this.arrowTipPosition,
emitRate: 100, emitRate: 100,
position: MyAvatar.position,
colorStart: { colorStart: {
red: 70, red: 70,
green: 70, green: 70,
@ -688,13 +689,13 @@
createArrowTracker: function(arrow, isBurning) { createArrowTracker: function(arrow, isBurning) {
print('in create arrow tracker:::' + arrow) print('in create arrow tracker:::' + arrow)
var _t = this; var _t = this;
var isBurning = isBurning || false; var isBurning = isBurning || true;
var arrowTracker = { var arrowTracker = {
arrowID: arrow, arrowID: arrow,
whizzingSound: _t.createWhizzingSound(), whizzingSound: _t.createWhizzingSound(),
fireSound: _t.createFireSound(), fireSound: _t.createFireSound(),
glowBox: _t.createGlowBox(), glowBox: _t.createGlowBox(),
fireParticleSystem: isBurning === true ? _t.createFireParticleSystem() : null, fireParticleSystem: _t.createFireParticleSystem(),
childEntities: [], childEntities: [],
childSounds: [], childSounds: [],
init: function() { init: function() {
@ -706,12 +707,12 @@
print('set arrow tracker callback' + this.arrowID) print('set arrow tracker callback' + this.arrowID)
Script.addEventHandler(this.arrowID, "collisionWithEntity", function(entityA, entityB, collision) { Script.addEventHandler(this.arrowID, "collisionWithEntity", function(entityA, entityB, collision) {
//how to get context here...? maybe reverse lookup the tracker by entityA (arrow) id, to get the glowbox etc. //have to reverse lookup the tracker by the arrow id to get access to the children
print('ARROW COLLIDED WITH SOMETHING!' + this.glowBox) var tracker = getArrowTrackerByArrowID(entityA);
//this is global print('ARROW COLLIDED WITH SOMETHING!' + tracker.glowBox)
print('THIS IN COLLISION !' + this) print('TRACKER IN COLLISION !' + tracker)
Entities.deleteEntity(this.glowBox); Entities.deleteEntity(tracker.glowBox);
//we don't want to update this arrow tracker anymore //we don't want to update this arrow tracker anymore
var index = _t.arrowTrackers.indexOf(entityA); var index = _t.arrowTrackers.indexOf(entityA);
if (index > -1) { if (index > -1) {
@ -721,15 +722,15 @@
}, },
setChildren: function() { setChildren: function() {
print('set arrow tracker children') print('set arrow tracker children')
// this.children.push(whizzingSound); // this.childSounds.push(this.whizzingSound);
// this.children.push(fireSound); // this.childSounds.push(this.fireSound);
this.childEntities.push(this.glowBox); this.childEntities.push(this.glowBox);
// this.children.push(fireParticleSystem); this.childEntities.push(this.fireParticleSystem);
}, },
updateChildEntities: function(arrowID) { updateChildEntities: function(arrowID) {
// print('ARROWID??'+arrowID) // print('ARROWID??'+arrowID)
// print('UPDATING CHILDREN OF TRACKER:::' + this.childEntities.length+" ARROW::"+arrowID); // print('UPDATING CHILDREN OF TRACKER:::' + this.childEntities.length+" ARROW::"+arrowID);
var arrowProperties = Entities.getEntityProperties(this.arrowID, ["position", "rotation"]) var arrowProperties = Entities.getEntityProperties(this.arrowID, ["position", "rotation"]);
this.childEntities.forEach(function(child) { this.childEntities.forEach(function(child) {
Entities.editEntity(child, { Entities.editEntity(child, {
position: arrowProperties.position, position: arrowProperties.position,
@ -752,6 +753,17 @@
var sound; var sound;
return sound return sound
}, },
createGlowBoxAsModel: function() {
var modelURL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/glowBox.fbx';
var properties = {
name: 'Hifi-Arrow-Glow',
type: 'Model',
modelURL: modelURL,
dimensions: ARROW_DIMENSIONS,
collisionsWillMove: false,
ignoreForCollisions: true,
}
},
createGlowBox: function() { createGlowBox: function() {
print('creating glow box') print('creating glow box')
var shaderUrl = Script.resolvePath('../../shaders/exampleV2.fs'); var shaderUrl = Script.resolvePath('../../shaders/exampleV2.fs');
@ -814,5 +826,13 @@
}; };
getArrowTrackerByArrowID = function(arrowID) {
var result = _this.arrowTrackers.filter(function(tracker) {
return tracker.arrowID === arrowID;
});
var tracker = result[0]
return tracker
}
return new Bow(); return new Bow();
}); });

View file

@ -36,7 +36,7 @@ var arrow;
function createArrow(i) { function createArrow(i) {
var center = Vec3.sum(Vec3.sum(MyAvatar.position, { var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0, x: 0,
y: 1, y: 0,
z: 0 z: 0
}), Vec3.multiply(1.25*i, Quat.getFront(Camera.getOrientation()))); }), Vec3.multiply(1.25*i, Quat.getFront(Camera.getOrientation())));

View file

@ -29,9 +29,9 @@ var BOW_GRAVITY = {
var center = Vec3.sum(Vec3.sum(MyAvatar.position, { var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0, x: 0,
y: 1, y: 0,
z: 0 z: 0
}), Vec3.multiply(1.5, Quat.getFront(Camera.getOrientation()))); }), Vec3.multiply(1, Quat.getFront(Camera.getOrientation())));
var bow = Entities.addEntity({ var bow = Entities.addEntity({
name: 'Hifi-Bow', name: 'Hifi-Bow',