redraw pre notch strings after firing

This commit is contained in:
James B. Pollack 2015-11-12 11:32:25 -08:00
parent c719f25fb2
commit 361a89ad46

View file

@ -88,7 +88,6 @@
Bow.prototype = { Bow.prototype = {
isGrabbed: false, isGrabbed: false,
stringDrawn: false, stringDrawn: false,
hasArrow: false,
arrowTipPosition: null, arrowTipPosition: null,
preNotchString: null, preNotchString: null,
hasArrowNotched: false, hasArrowNotched: false,
@ -144,7 +143,7 @@
//check to see if an arrow has notched itself in our notch detector //check to see if an arrow has notched itself in our notch detector
var userData = JSON.parse(this.bowProperties.userData); var userData = JSON.parse(this.bowProperties.userData);
if (userData.hasOwnProperty('hifiBowKey')) { if (userData.hasOwnProperty('hifiBowKey')) {
if (this.hasArrowNotched === false) { if (this.hasArrowNotched === false && userData.hifiBowKey.arrowID!==null) {
//notch the arrow //notch the arrow
print('NOTCHING IT!') print('NOTCHING IT!')
this.hasArrowNotched = userData.hifiBowKey.hasArrowNotched; this.hasArrowNotched = userData.hifiBowKey.hasArrowNotched;
@ -159,32 +158,42 @@
} }
//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')
this.createPreNotchString(); this.createPreNotchString();
} }
if (this.preNotchString !== null && this.hasArrowNotched === false) { if (this.preNotchString !== null && this.hasArrowNotched === false) {
print('DRAW PRE NOTCH STRING')
this.drawPreNotchStrings(); this.drawPreNotchStrings();
} }
// create the notch detector that arrows will look for // create the notch detector that arrows will look for
if (this.notchDetector === null) { if (this.notchDetector === null) {
print('CREATE NOTCH DETECTOR')
this.createNotchDetector(); this.createNotchDetector();
} }
//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.preNotchString !== null) {
Entities.deleteEntity(this.preNotchString); print('MAKE PRE NOTCH INVISIBLE')
Entities.editEntity(this.preNotchString, {
visible: false
});
} }
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 {
//otherwise, don't do much of anything. print('DONT DO ANYTHING')
//otherwise, don't do much of anything.
} }
}, },
@ -195,7 +204,7 @@
this.stringDrawn = false; this.stringDrawn = false;
this.deleteStrings(); this.deleteStrings();
this.hasArrow = false; this.hasArrow = false;
// Entities.deleteEntity(this.arrow); Entities.deleteEntity(this.arrow);
setEntityCustomData('grabbableKey', this.entityID, { setEntityCustomData('grabbableKey', this.entityID, {
turnOffOtherHand: false, turnOffOtherHand: false,
invertSolidWhileHeld: true invertSolidWhileHeld: true
@ -376,10 +385,9 @@
// firing the arrow // firing the arrow
print('HIT RELEASE LOOP IN CHECK') print('HIT RELEASE LOOP IN CHECK')
// this.stringDrawn = false;
// this.deleteStrings();
// this.hasArrow = false; 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')
@ -421,7 +429,6 @@
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition); var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
print('h2n:::' + JSON.stringify(handToNotch))
var pullBackDistance = Vec3.length(handToNotch); var pullBackDistance = Vec3.length(handToNotch);
if (pullBackDistance >= 0.6) { if (pullBackDistance >= 0.6) {
@ -434,20 +441,13 @@
var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET); var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET);
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);
print('ARROW ROTATION:: ' + JSON.stringify(arrowRotation));
Entities.editEntity(this.arrow, { Entities.editEntity(this.arrow, {
position: finalArrowPosition, position: finalArrowPosition,
rotation: arrowRotation rotation: arrowRotation
}) })
var currentRotation = Entities.getEntityProperties(this.arrow, "rotation").rotation
// print('ACTUAL ARROW ROTATION::' +JSON.stringify(currentRotation));
// print('DIFFERENCE::: ' + (1 - Quat.dot(arrowRotation, currentRotation)));
// if (this.arrowIsBurning === true) { // if (this.arrowIsBurning === true) {
// Entities.editEntity(this.fire, { // Entities.editEntity(this.fire, {
// position: arrowTipPosition // position: arrowTipPosition
@ -463,38 +463,45 @@
var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition); var handToNotch = Vec3.subtract(this.notchDetectorPosition, this.stringData.handPosition);
var pullBackDistance = Vec3.length(handToNotch); var pullBackDistance = Vec3.length(handToNotch);
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch); var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
print('HAND DISTANCE:: ' + pullBackDistance); print('HAND DISTANCE:: ' + pullBackDistance);
var arrowForce = this.scaleArrowShotStrength(pullBackDistance, 0, 2, 20, 50); var arrowForce = this.scaleArrowShotStrength(pullBackDistance, 0, 2, 20, 50);
print('ARROW FORCE::' + arrowForce); print('ARROW FORCE::' + arrowForce);
var forwardVec = Vec3.multiply(handToNotch, arrowForce); var forwardVec = Vec3.multiply(handToNotch, arrowForce);
print('FWD VEC:::' + JSON.stringify(forwardVec));
var arrowProperties = { var arrowProperties = {
// rotation:handToHand, rotation: arrowRotation,
velocity: forwardVec velocity: forwardVec
}; };
Entities.editEntity(this.arrow, arrowProperties); setEntityCustomData('hifiBowKey', this.entityID, {
Script.setTimeout(function() { hasArrowNotched: false,
arrowID: null
});
Entities.editEntity(this.arrow, arrowProperties);
this.arrow = null;
this.hasArrowNotched = false;
Entities.editEntity(this.preNotchString, {
visible: true
});
this.stringDrawn = false;
this.deleteStrings();
Script.setTimeout(function() {
print('making arrow physical')
Entities.editEntity(this.arrow, { Entities.editEntity(this.arrow, {
ignoreForCollisions: false, ignoreForCollisions: false,
collisionsWillMove: true, collisionsWillMove: true,
gravity: ARROW_GRAVITY gravity: ARROW_GRAVITY
}); });
}, 200)
}, 100)
print('ARROW collisions??:::' + Entities.getEntityProperties(this.arrow, "collisionsWillMove").collisionsWillMove);
print('ARROW velocity:::' + JSON.stringify(Entities.getEntityProperties(this.arrow, "velocity").velocity))
this.arrow = null;
this.hasArrowNotched = false;
this.fire = null;
this.arrowIsBurnning = false;
}, },