make bow equippable and change it so you dont have to load arrows

This commit is contained in:
James B. Pollack 2015-11-18 15:33:47 -08:00
parent ac336af9b5
commit 328950065f
7 changed files with 182 additions and 443 deletions

View file

@ -155,14 +155,14 @@ spawnGround();
spawnBoxes(); spawnBoxes();
function cleanup() { // function cleanup() {
Entities.deleteEntity(ground); // Entities.deleteEntity(ground);
boxes.forEach(function(box) { // boxes.forEach(function(box) {
Entities.deleteEntity(box); // Entities.deleteEntity(box);
}); // });
dustSystems.forEach(function(dustEffect) { // dustSystems.forEach(function(dustEffect) {
Entities.deleteEntity(dustEffect); // Entities.deleteEntity(dustEffect);
}) // })
} // }
Script.scriptEnding.connect(cleanup); // Script.scriptEnding.connect(cleanup);

View file

@ -1,241 +0,0 @@
//
// arrow.js
//
// This script attaches to an arrow to make it stop and stick when it hits something. Could use this to make it a fire arrow or really give any kind of property to itself or the entity it hits.
//
// Created by James B. Pollack @imgntn on 10/19/2015
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
Script.include("../../libraries/utils.js");
var NOTCH_DETECTOR_SEARCH_RADIUS = 0.25;
var FIRE_DETECTOR_SEARCH_RADIUS = 0.25;
var _this;
function Arrow() {
_this = this;
return;
}
Arrow.prototype = {
stickOnCollision: false,
notched: false,
isBurning: false,
fire: null,
preload: function(entityID) {
this.entityID = entityID;
},
releaseGrab: function() {
if (this.fire !== null) {
this.fire = null;
this.isBurning = false;
Entities.deleteEntity(this.fire);
}
},
continueNearGrab: function() {
this.currentProperties = Entities.getEntityProperties(this.entityID, "position");
if(this.notched===true){
return;
}
if (this.isBurning !== true) {
this.searchForFires();
} else {
this.updateFirePosition();
}
if (this.notched !== true) {
this.searchForNotchDetectors();
}
},
searchForNotchDetectors: function() {
if (this.notched === true) {
return
};
var ids = Entities.findEntities(this.currentProperties.position, NOTCH_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-NotchDetector") {
print('NEAR THE NOTCH!!!')
this.notched = true;
this.tellBowArrowIsNotched(this.getBowID(id));
}
}
},
searchForFires: function() {
print('SEARCHING FOR FIRES!')
if (this.notched === true) {
return
};
if (this.isBurning === 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.isBurning = true;
this.createFireParticleSystem();
}
}
},
updateFirePosition: function() {
print('updating fire position' + this.fire)
Entities.editEntity(this.fire, {
position: this.currentProperties.position
})
},
createFireParticleSystem: function() {
print('CREATING FIRE PARTICLE SYSTEM')
var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0);
var animationSettings = JSON.stringify({
fps: 30,
running: true,
loop: true,
firstFrame: 1,
lastFrame: 10000
});
this.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.currentProperties.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.15,
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
});
},
getBowID: function(notchDetectorID) {
var properties = Entities.getEntityProperties(notchDetectorID, "userData");
var userData = JSON.parse(properties.userData);
if (userData.hasOwnProperty('hifiBowKey')) {
return userData.hifiBowKey.bowID;
}
},
getActionID: function() {
var properties = Entities.getEntityProperties(this.entityID, "userData");
var userData = JSON.parse(properties.userData);
if (userData.hasOwnProperty('hifiHoldActionKey')) {
return userData.hifiHoldActionKey.holdActionID;
}
},
disableGrab: function() {
var actionID = this.getActionID();
var success = Entities.deleteAction(this.entityID, actionID);
},
tellBowArrowIsNotched: function(bowID) {
this.disableGrab();
setEntityCustomData('grabbableKey', this.entityID, {
grabbable: false,
invertSolidWhileHeld: true
});
Entities.editEntity(this.entityID, {
collisionsWillMove: true,
ignoreForCollisions: false,
gravity:{
x:0,
y:-5.8,
z:0
}
})
setEntityCustomData('hifiBowKey', bowID, {
hasArrowNotched: true,
arrowIsBurning: this.isBurning,
arrowID: this.entityID
});
if (this.isBurning === true) {
this.isBurning = false;
this.fire = null;
Entities.deleteEntity(this.fire);
}
},
}
function deleteEntity(entityID) {
if (entityID === _this.entityID) {
if (_this.isBurning === true) {
Entities.deleteEntity(_this.fire);
}
}
}
Entities.deletingEntity.connect(deleteEntity);
return new Arrow;
})

View file

@ -50,10 +50,21 @@
var ARROW_TIP_OFFSET = 0.32; var ARROW_TIP_OFFSET = 0.32;
var ARROW_GRAVITY = { var ARROW_GRAVITY = {
x: 0, x: 0,
y: -5.8, y: -4.8,
z: 0 z: 0
}; };
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow.fbx";
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow_collision_hull.obj";
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
var ARROW_DIMENSIONS = {
x: 0.02,
y: 0.02,
z: 0.64
};
var TOP_NOTCH_OFFSET = 0.6; var TOP_NOTCH_OFFSET = 0.6;
var BOTTOM_NOTCH_OFFSET = 0.6; var BOTTOM_NOTCH_OFFSET = 0.6;
@ -84,10 +95,18 @@
var SHOT_SCALE = { var SHOT_SCALE = {
min1: 0, min1: 0,
max1: 0.6, max1: 0.6,
min2: 3, min2: 1,
max2: 15 max2: 10
} }
var BOW_SPATIAL_KEY = {
relativePosition: {
x: 0,
y: 0.06,
z: 0.11
},
relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90)
}
var _this; var _this;
@ -105,12 +124,13 @@
Bow.prototype = { Bow.prototype = {
isGrabbed: false, isGrabbed: false,
stringDrawn: false, stringDrawn: false,
aiming: false,
arrowTipPosition: null, arrowTipPosition: null,
preNotchString: null, preNotchString: null,
hasArrowNotched: false, hasArrowNotched: false,
notchDetector: null, notchDetector: null,
arrow: null, arrow: null,
arrowIsBurning:false, arrowIsBurning: false,
stringData: { stringData: {
currentColor: { currentColor: {
red: 255, red: 255,
@ -134,6 +154,22 @@
unload: function() { unload: function() {
Script.update.disconnect(this.updateArrowTrackers); Script.update.disconnect(this.updateArrowTrackers);
while (this.arrowTrackers.length > 0) {
var tracker = this.arrowTrackers.pop();
tracker.childEntities.forEach(function(child) {
Entities.deleteEntity(child);
})
tracker.childParticleSystems.forEach(function(child) {
Entities.deleteEntity(child);
})
Entities.deleteEntity(tracker.arrowID);
}
this.deleteStrings();
Entities.deleteEntity(this.notchDetector);
Entities.deleteEntity(this.preNotchString);
Entities.deleteEntity(this.arrow);
Script.clearInterval(physicalArrowInterval);
}, },
setLeftHand: function() { setLeftHand: function() {
@ -159,7 +195,8 @@
setEntityCustomData('grabbableKey', this.entityID, { setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: true, turnOffOtherHand: true,
invertSolidWhileHeld: true invertSolidWhileHeld: true,
spatialKey: BOW_SPATIAL_KEY
}); });
}, },
@ -177,40 +214,30 @@
this.updateNotchDetectorPosition(); this.updateNotchDetectorPosition();
//check to see if an arrow has notched itself in our notch detector if (this.hasArrowNotched === false) {
var userData = JSON.parse(this.bowProperties.userData); this.playArrowNotchSound();
if (userData.hasOwnProperty('hifiBowKey')) { this.playStringPullSound();
if (this.hasArrowNotched === false && userData.hifiBowKey.arrowID !== null) { this.hasArrowNotched = true
//notch the arrow this.arrow = this.createArrow();
print('NOTCHING IT!') print('NOTCH ARROW' + this.arrow);
this.playArrowNotchSound(); this.arrowIsBurning = false
this.playStringPullSound(); setEntityCustomData('grabbableKey', this.entityID, {
this.hasArrowNotched = userData.hifiBowKey.hasArrowNotched; turnOffOtherHand: true,
invertSolidWhileHeld: true,
this.arrow = userData.hifiBowKey.arrowID; spatialKey: BOW_SPATIAL_KEY
this.arrowIsBurning = userData.hifiBowKey.arrowIsBurning; });
setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: true,
invertSolidWhileHeld: true
});
}
} }
//this.arrow
//this.hasArrowNotched
//create a string across the bow when we pick it up //create a string across the bow when we pick it up
if (this.preNotchString === null) { if (this.preNotchString === null) {
print('CREATE PRE NOTCH STRING') print('CREATE PRE NOTCH STRING')
this.createPreNotchString(); this.createPreNotchString();
} }
if (this.preNotchString !== null && this.hasArrowNotched === false) { if (this.preNotchString !== null && this.aiming === false) {
// print('DRAW PRE NOTCH STRING') // print('DRAW PRE NOTCH STRING')
this.drawPreNotchStrings(); this.drawPreNotchStrings();
this.updateArrowAttachedToBow();
} }
// create the notch detector that arrows will look for // create the notch detector that arrows will look for
@ -220,16 +247,17 @@
//if we have an arrow notched, then draw some new strings //if we have an arrow notched, then draw some new strings
if (this.hasArrowNotched === true) { if (this.hasArrowNotched === true) {
if (this.preNotchString !== null) { if (this.aiming === true) {
// print('MAKE PRE NOTCH INVISIBLE')
Entities.editEntity(this.preNotchString, { Entities.editEntity(this.preNotchString, {
visible: false visible: false
}); })
} else {
Entities.editEntity(this.preNotchString, {
visible: true
})
} }
// print('CHECK STRING HAND')
//only test for strings now that an arrow is notched //only test for strings now that an arrow is notched
this.checkStringHand(); this.checkStringHand();
} else { } else {
@ -240,23 +268,48 @@
}, },
releaseGrab: function() { releaseGrab: function() {
print('RELEASE GRAB EVENT')
if (this.isGrabbed === true && this.hand === this.initialHand) { if (this.isGrabbed === true && this.hand === this.initialHand) {
this.isGrabbed = false; this.isGrabbed = false;
this.stringDrawn = false; this.stringDrawn = false;
this.deleteStrings(); this.deleteStrings();
setEntityCustomData('grabbableKey', this.entityID, { setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: false, turnOffOtherHand: false,
invertSolidWhileHeld: true invertSolidWhileHeld: true,
spatialKey: BOW_SPATIAL_KEY
}); });
Entities.deleteEntity(this.notchDetector); Entities.deleteEntity(this.notchDetector);
Entities.deleteEntity(this.preNotchString); Entities.deleteEntity(this.preNotchString);
Entities.deleteEntity(this.arrow);
this.aiming = false;
this.notchDetector = null; this.notchDetector = null;
this.hasArrowNotched = false;
this.preNotchString = null; this.preNotchString = null;
} }
}, },
createArrow: function() {
var arrow = Entities.addEntity({
name: 'Hifi-Arrow',
type: 'Model',
modelURL: ARROW_MODEL_URL,
shapeType: 'compound',
compoundShapeURL: ARROW_COLLISION_HULL_URL,
dimensions: ARROW_DIMENSIONS,
position: this.bowProperties.position,
script: ARROW_SCRIPT_URL,
collisionsWillMove: false,
ignoreForCollisions: true,
collisionSoundURL: 'http://hifi-content.s3.amazonaws.com/bow_and_arrow/sounds/Arrow_impact1.L.wav',
gravity: ARROW_GRAVITY,
linearDamping: 0.01
});
return arrow
},
createStrings: function() { createStrings: function() {
this.createTopString(); this.createTopString();
this.createBottomString(); this.createBottomString();
@ -264,6 +317,7 @@
createTopString: function() { createTopString: function() {
var stringProperties = { var stringProperties = {
name: 'Hifi-Bow-Top-String',
type: 'Line', type: 'Line',
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET), position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
dimensions: LINE_DIMENSIONS, dimensions: LINE_DIMENSIONS,
@ -281,6 +335,7 @@
createBottomString: function() { createBottomString: function() {
var stringProperties = { var stringProperties = {
name: 'Hifi-Bow-Bottom-String',
type: 'Line', type: 'Line',
position: Vec3.sum(this.bowProperties.position, BOTTOM_NOTCH_OFFSET), position: Vec3.sum(this.bowProperties.position, BOTTOM_NOTCH_OFFSET),
dimensions: LINE_DIMENSIONS, dimensions: LINE_DIMENSIONS,
@ -302,7 +357,6 @@
}, },
updateStringPositions: function() { updateStringPositions: function() {
var upVector = Quat.getUp(this.bowProperties.rotation); var upVector = Quat.getUp(this.bowProperties.rotation);
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET); var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation)); var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
@ -313,7 +367,6 @@
this.topStringPosition = Vec3.sum(topStringPosition, backOffset); this.topStringPosition = Vec3.sum(topStringPosition, backOffset);
var bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset); var bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
this.bottomStringPosition = Vec3.sum(bottomStringPosition, backOffset); this.bottomStringPosition = Vec3.sum(bottomStringPosition, backOffset);
Entities.editEntity(this.topString, { Entities.editEntity(this.topString, {
position: this.topStringPosition position: this.topStringPosition
}); });
@ -321,7 +374,6 @@
Entities.editEntity(this.bottomString, { Entities.editEntity(this.bottomString, {
position: this.bottomStringPosition position: this.bottomStringPosition
}); });
Entities.editEntity(this.preNotchString, { Entities.editEntity(this.preNotchString, {
position: this.topStringPosition position: this.topStringPosition
}); });
@ -355,20 +407,18 @@
}, },
getLocalLineVectors: function() { getLocalLineVectors: function() {
var topVector = Vec3.subtract(this.stringData.handPosition, this.topStringPosition); var topVector = Vec3.subtract(this.arrowRearPosition, this.topStringPosition);
var bottomVector = Vec3.subtract(this.stringData.handPosition, this.bottomStringPosition); var bottomVector = Vec3.subtract(this.arrowRearPosition, this.bottomStringPosition);
return [topVector, bottomVector]; return [topVector, bottomVector];
}, },
createPreNotchString: function() { createPreNotchString: function() {
var stringProperties = { var stringProperties = {
type: 'Line', type: 'Line',
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET), position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
dimensions: LINE_DIMENSIONS, dimensions: LINE_DIMENSIONS,
visible: true,
userData: JSON.stringify({ userData: JSON.stringify({
grabbableKey: { grabbableKey: {
grabbable: false grabbable: false
@ -380,13 +430,11 @@
}, },
drawPreNotchStrings: function() { drawPreNotchStrings: function() {
this.updateStringPositions(); this.updateStringPositions();
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation)); var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET * 2); var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET * 2);
Entities.editEntity(this.preNotchString, { Entities.editEntity(this.preNotchString, {
linePoints: [{ linePoints: [{
x: 0, x: 0,
@ -424,13 +472,14 @@
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) { if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
// firing the arrow // firing the arrow
print('HIT RELEASE LOOP IN CHECK') // print('HIT RELEASE LOOP IN CHECK')
this.releaseArrow(); this.releaseArrow();
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === true) { } else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
print('HIT CONTINUE LOOP IN CHECK') // print('HIT CONTINUE LOOP IN CHECK')
this.aiming = true;
//continuing to aim the arrow //continuing to aim the arrow
this.stringData.handPosition = this.getStringHandPosition(); this.stringData.handPosition = this.getStringHandPosition();
this.stringData.handRotation = this.getStringHandRotation(); this.stringData.handRotation = this.getStringHandRotation();
@ -440,8 +489,8 @@
this.updateArrowPositionInNotch(); this.updateArrowPositionInNotch();
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === false) { } else if (this.triggerValue >= DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
print('HIT START LOOP IN CHECK') // print('HIT START LOOP IN CHECK')
//the first time aiming the arrow //the first time aiming the arrow
this.stringDrawn = true; this.stringDrawn = true;
this.createStrings(); this.createStrings();
var arrowTracker = this.createArrowTracker(this.arrow); var arrowTracker = this.createArrowTracker(this.arrow);
@ -465,6 +514,14 @@
this.arrowTipPosition = arrowTipPosition; this.arrowTipPosition = arrowTipPosition;
return arrowTipPosition; return arrowTipPosition;
},
setArrowRearPosition: function(arrowPosition, arrowRotation) {
var frontVector = Quat.getFront(arrowRotation);
var frontOffset = Vec3.multiply(frontVector, -ARROW_TIP_OFFSET);
var arrowTipPosition = Vec3.sum(arrowPosition, frontOffset);
this.arrowRearPosition = arrowTipPosition;
return arrowTipPosition;
}, },
getArrowPosition: function() { getArrowPosition: function() {
var arrowVector = Vec3.subtract(this.stringData.handPosition, this.stringData.grabHandPosition); var arrowVector = Vec3.subtract(this.stringData.handPosition, this.stringData.grabHandPosition);
@ -474,6 +531,13 @@
return arrowPosition; return arrowPosition;
}, },
updateArrowAttachedToBow: function() {
Entities.editEntity(this.arrow, {
position: this.notchDetectorPosition,
rotation: this.bowProperties.rotation
})
},
updateArrowPositionInNotch: function() { updateArrowPositionInNotch: function() {
//move it backwards //move it backwards
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition); var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
@ -491,7 +555,8 @@
var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset); var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset);
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch); var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
// this.setArrowTipPosition(finalArrowPosition, arrowRotation); this.setArrowTipPosition(finalArrowPosition, arrowRotation);
this.setArrowRearPosition(finalArrowPosition, arrowRotation);
Entities.editEntity(this.arrow, { Entities.editEntity(this.arrow, {
position: finalArrowPosition, position: finalArrowPosition,
rotation: arrowRotation rotation: arrowRotation
@ -514,25 +579,23 @@
var arrowForce = this.scaleArrowShotStrength(pullBackDistance); var arrowForce = this.scaleArrowShotStrength(pullBackDistance);
print('ARROW FORCE::' + arrowForce); print('ARROW FORCE::' + arrowForce);
handToNotch = Vec3.normalize(handToNotch) handToNotch = Vec3.normalize(handToNotch)
var forwardVec=handToNotch; // var forwardVec = handToNotch;
// var forwardVec = Vec3.multiply(handToNotch, arrowForce); var forwardVec = Vec3.multiply(handToNotch, arrowForce);
var arrowProperties = { var arrowProperties = {
// rotation: arrowRotation, // rotation: arrowRotation,
velocity: forwardVec velocity: forwardVec,
}; };
this.playShootArrowSound(); this.playShootArrowSound();
Entities.editEntity(this.arrow, arrowProperties);
setEntityCustomData('hifiBowKey', this.entityID, { Entities.editEntity(this.arrow, arrowProperties);
hasArrowNotched: false,
arrowID: null
});
var arrowStore = this.arrow; var arrowStore = this.arrow;
this.arrow = null; this.arrow = null;
this.hasArrowNotched = false; this.hasArrowNotched = false;
this.aiming = false;
Entities.editEntity(this.preNotchString, { Entities.editEntity(this.preNotchString, {
visible: true visible: true
@ -543,37 +606,25 @@
//set an itnerval to heck how far the arrow is from the bow before adding gravity, etc. if we add this too soon, the arrow collides with the bow. hence, this function //set an itnerval to heck how far the arrow is from the bow before adding gravity, etc. if we add this too soon, the arrow collides with the bow. hence, this function
// this.physicalArrowInterval = Script.setInterval(function() { var physicalArrowInterval = Script.setInterval(function() {
// print('in physical interval') print('in physical interval')
// var arrowProps = Entities.getEntityProperties(arrowStore, "position"); var arrowProps = Entities.getEntityProperties(arrowStore, "position");
// var bowProps = Entities.getEntityProperties(_this.entityID, "position"); var bowProps = Entities.getEntityProperties(_this.entityID, "position");
// var arrowPosition = arrowProps.position; var arrowPosition = arrowProps.position;
// var bowPosition = bowProps.position; var bowPosition = bowProps.position;
// var length = Vec3.distance(arrowPosition, bowPosition); var length = Vec3.distance(arrowPosition, bowPosition);
// print('LENGTH:::' + length); print('LENGTH:::' + length);
// if (length > 2) { if (length > 2) {
// print('make arrow physical' + arrowStore) print('make arrow physical' + arrowStore)
// Entities.editEntity(arrowStore, { Entities.editEntity(arrowStore, {
// ignoreForCollisions: false, ignoreForCollisions: false,
// collisionsWillMove: true, collisionsWillMove: true
// gravity: ARROW_GRAVITY });
// }); var arrowProps = Entities.getEntityProperties(arrowStore)
// print('after make physical' + arrowStore) Script.clearInterval(physicalArrowInterval);
// var arrowProps = Entities.getEntityProperties(arrowStore) }
// print('arrowprops-collisions::' + arrowProps.collisionsWillMove); }, 5)
// print('arrowprops-graviy' + JSON.stringify(arrowProps.gravity));
// Script.setTimeout(function() {
// print('in timeout :: ' + arrowStore)
// var arrowProps = Entities.getEntityProperties(arrowStore)
// print('arrowprops-gravity2' + JSON.stringify(arrowProps.gravity));
// print('ARROW USER DATA::' + arrowProps.userData)
// }, 1000)
// Script.clearInterval(_this.physicalArrowInterval)
// }
// }, 10)
}, },
@ -608,12 +659,7 @@
red: 0, red: 0,
green: 255, green: 255,
blue: 0 blue: 0
}, }
userData: JSON.stringify({
hifiBowKey: {
bowID: this.entityID
}
})
}; };
this.notchDetector = Entities.addEntity(detectorProperties); this.notchDetector = Entities.addEntity(detectorProperties);
@ -699,7 +745,9 @@
y: 0.01, y: 0.01,
z: 0.1 z: 0.1
}, },
lifespan: 0.5 lifespan: 0.5,
ignoreForCollisions: true,
collisionsWillMove: false,
}); });
return fire; return fire;
@ -717,7 +765,7 @@
// whizzingSound: _t.playWhizzSound(), // whizzingSound: _t.playWhizzSound(),
//fireSound: _t.createFireSound(), //fireSound: _t.createFireSound(),
hasPlayedCollisionSound: false, hasPlayedCollisionSound: false,
glowBox: _t.createGlowBox(), glowBox: _t.createGlowBoxAsModel(),
fireParticleSystem: _t.createFireParticleSystem(), fireParticleSystem: _t.createFireParticleSystem(),
childEntities: [], childEntities: [],
childSounds: [], childSounds: [],
@ -734,8 +782,8 @@
//have to reverse lookup the tracker by the arrow id to get access to the children //have to reverse lookup the tracker by the arrow id to get access to the children
var tracker = getArrowTrackerByArrowID(entityA); var tracker = getArrowTrackerByArrowID(entityA);
var bProps = Entities.getEntityProperties(entityB,"name") var bProps = Entities.getEntityProperties(entityB, "name")
print('ARROW COLLIDED WITH SOMETHING!'+bProps.name) print('ARROW COLLIDED WITH SOMETHING!' + bProps.name)
print('TRACKER IN COLLISION !' + tracker) print('TRACKER IN COLLISION !' + tracker)
// _t.playArrowHitSound(collision.contactPoint); // _t.playArrowHitSound(collision.contactPoint);
//Vec3.print('penetration = ', collision.penetration); //Vec3.print('penetration = ', collision.penetration);
@ -760,7 +808,8 @@
// print('UPDATING CHILDREN OF TRACKER:::' + this.childEntities.length); // print('UPDATING CHILDREN OF TRACKER:::' + this.childEntities.length);
var arrowProperties = Entities.getEntityProperties(this.arrowID, ["position", "rotation"]); var arrowProperties = Entities.getEntityProperties(this.arrowID, ["position", "rotation"]);
_t.setArrowTipPosition(arrowProperties.position, arrowProperties.rotation);
_t.setArrowRearPosition(arrowProperties.position, arrowProperties.rotation);
//update the positions //update the positions
// this.soundEntities.forEach(function(injector) { // this.soundEntities.forEach(function(injector) {
// var audioProperties = { // var audioProperties = {
@ -779,7 +828,7 @@
this.childParticleSystems.forEach(function(child) { this.childParticleSystems.forEach(function(child) {
Entities.editEntity(child, { Entities.editEntity(child, {
position: arrowProperties.position position: _t.arrowTipPosition
}) })
}) })
@ -803,15 +852,22 @@
return injector return injector
}, },
createGlowBoxAsModel: function() { createGlowBoxAsModel: function() {
var modelURL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/glowBox.fbx'; var GLOW_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/glow.fbx';
var properties = { var properties = {
name: 'Hifi-Arrow-Glow', name: 'Hifi-Arrow-Glow-Model',
type: 'Model', type: 'Model',
modelURL: modelURL, modelURL: GLOW_MODEL_URL,
dimensions: ARROW_DIMENSIONS, dimensions: ARROW_DIMENSIONS,
collisionsWillMove: false, collisionsWillMove: false,
ignoreForCollisions: true, ignoreForCollisions: true,
userData: JSON.stringify({
grabbableKey: {
grabbable: false
}
})
} }
var glowBox = Entities.addEntity(properties);
return glowBox
}, },
createGlowBox: function() { createGlowBox: function() {
print('creating glow box') print('creating glow box')

View file

@ -1,74 +0,0 @@
//
// createArrow.js
//
// Created byJames Pollack @imgntn on 10/19/2015
// Copyright 2015 High Fidelity, Inc.
//
// This script creates a bow you can use to shoot an arrow.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var ARROW_MODEL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow.fbx";
var ARROW_COLLISION_HULL_URL = "https://hifi-public.s3.amazonaws.com/models/bow/new/arrow_collision_hull.obj";
var ARROW_SCRIPT_URL = Script.resolvePath('arrow.js');
var ARROW_DIMENSIONS = {
x: 0.02,
y: 0.02,
z: 0.64
};
var ARROW_GRAVITY = {
x: 0,
y: 0,
z: 0
};
function cleanup() {
Entities.deleteEntity(arrow);
}
var arrow;
function createArrow(i) {
var center = Vec3.sum(Vec3.sum(MyAvatar.position, {
x: 0,
y: 0.5,
z: 0
}), Vec3.multiply(1.25*i, Quat.getFront(Camera.getOrientation())));
arrow = Entities.addEntity({
name: 'Hifi-Arrow',
type: 'Model',
modelURL: ARROW_MODEL_URL,
shapeType: 'compound',
compoundShapeURL: ARROW_COLLISION_HULL_URL,
dimensions: ARROW_DIMENSIONS,
position: center,
script: ARROW_SCRIPT_URL,
collisionsWillMove: true,
ignoreForCollisions: false,
collisionSoundURL:'http://hifi-content.s3.amazonaws.com/bow_and_arrow/sounds/Arrow_impact1.L.wav',
gravity: ARROW_GRAVITY,
linearDamping:0.01,
userData: JSON.stringify({
grabbableKey: {
invertSolidWhileHeld: true
}
})
});
}
var i;
for(i=1;i<6;i++){
createArrow(i);
}
Script.scriptEnding.connect(cleanup);

View file

@ -50,8 +50,8 @@ var bow = Entities.addEntity({
spatialKey: { spatialKey: {
relativePosition: { relativePosition: {
x: 0, x: 0,
y: 0.1, y: 0.06,
z: 0 z: 0.11
}, },
relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90) relativeRotation: Quat.fromPitchYawRollDegrees(0, -90, 90)
} }

View file

@ -1,2 +0,0 @@
Script.include("createBow.js");
Script.include("createArrow.js");

View file

@ -1,4 +1,4 @@
// arrowFieldSpawner.js // fieldSpawner.js
// examples // examples
// //
// Created by James B. Pollack @imgntn on 11/16/2015 // Created by James B. Pollack @imgntn on 11/16/2015
@ -95,12 +95,12 @@ spawnGround();
spawnBoxes(); spawnBoxes();
function cleanup() { // function cleanup() {
Entities.deleteEntity(ground); // Entities.deleteEntity(ground);
boxes.forEach(function(box) { // boxes.forEach(function(box) {
Entities.deleteEntity(box); // Entities.deleteEntity(box);
}); // });
} // }
Script.scriptEnding.connect(cleanup); // Script.scriptEnding.connect(cleanup);