diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 8669a1c4d3..0d2cae0bd8 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -101,6 +101,8 @@ public: std::shared_ptr myAvatarZone() { return _layeredZones.getZone(); } + QSharedPointer getEntitiesScriptEngine() const { return _entitiesScriptEngine; } + signals: void mousePressOnEntity(const EntityItemID& entityItemID, const PointerEvent& event); void mouseMoveOnEntity(const EntityItemID& entityItemID, const PointerEvent& event); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 19ab19abb8..978436e089 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -905,7 +905,8 @@ void ScriptEngine::run() { // that some of our script udpates/frames take a little bit longer than the target average // to execute. // NOTE: if we go to variable SCRIPT_FPS, then we will need to reconsider this approach - const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(static_cast(USECS_PER_SECOND / _getTargetUpdateRate()) + 1); + //const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(static_cast(USECS_PER_SECOND / _getTargetUpdateRate()) + 1); + const std::chrono::microseconds TARGET_SCRIPT_FRAME_DURATION(static_cast(USECS_PER_SECOND / 75.0f) + 1); clock::time_point targetSleepUntil(startTime + (thisFrame++ * TARGET_SCRIPT_FRAME_DURATION)); // However, if our sleepUntil is not at least our average update and timer execution time diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js index fc3a7948af..c572da3f5d 100644 --- a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js @@ -170,7 +170,6 @@ getControllerWorldLocation = function (handController, doOffset) { const STATE_IDLE = 0; const STATE_ARROW_KNOCKED = 1; const STATE_ARROW_GRABBED = 2; - const STATE_ARROW_GRABBED_AND_PULLED = 3; Bow.prototype = { topString: null, @@ -196,6 +195,7 @@ getControllerWorldLocation = function (handController, doOffset) { this.arrowHitSound = SoundCache.getSound(ARROW_HIT_SOUND_URL); this.arrowNotchSound = SoundCache.getSound(NOTCH_ARROW_SOUND_URL); var userData = Entities.getEntityProperties(this.entityID, ["userData"]).userData; + print(userData); this.userData = JSON.parse(userData); this.stringID = null; }, @@ -420,59 +420,63 @@ getControllerWorldLocation = function (handController, doOffset) { this.resetStringToIdlePosition(); //this.deleteStrings(); - if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE - NEAR_TO_RELAXED_SCHMITT) && !this.backHandBusy) { + if (this.triggerValue >= DRAW_STRING_THRESHOLD && pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE - NEAR_TO_RELAXED_SCHMITT) && !this.backHandBusy) { //the first time aiming the arrow + var handToDisable = (this.hand === 'right' ? 'left' : 'right'); + this.state = STATE_ARROW_GRABBED; + } + } + //if (this.state === STATE_ARROW_KNOCKED) { + + // if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) { + // // delete the unpulled arrow + // Messages.sendLocalMessage('Hifi-Hand-Disabler', "none"); + // this.state = STATE_IDLE; + // } else if (this.triggerValue >= DRAW_STRING_THRESHOLD) { + // // they've grabbed the arrow + // this.pullBackDistance = 0; + // this.state = STATE_ARROW_GRABBED; + // } + //} + if (this.state === STATE_ARROW_GRABBED) { + if (!this.arrow) { var handToDisable = (this.hand === 'right' ? 'left' : 'right'); Messages.sendLocalMessage('Hifi-Hand-Disabler', handToDisable); this.arrow = this.createArrow(); this.playStringPullSound(); - this.state = STATE_ARROW_KNOCKED; } - } - if (this.state === STATE_ARROW_KNOCKED) { - if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) { - // delete the unpulled arrow - Messages.sendLocalMessage('Hifi-Hand-Disabler', "none"); - Entities.deleteEntity(this.arrow); - this.arrow = null; - this.state = STATE_IDLE; - } else if (this.triggerValue >= DRAW_STRING_THRESHOLD) { - // they've grabbed the arrow - this.pullBackDistance = 0; - this.state = STATE_ARROW_GRABBED; - } else { - this.updateArrowPositionInNotch(false, false); - this.updateString(); - } - } - if (this.state === STATE_ARROW_GRABBED) { if (this.triggerValue < DRAW_STRING_THRESHOLD) { // they let go without pulling - this.state = STATE_ARROW_KNOCKED; - } else if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) { - // they've grabbed the arrow and pulled it - this.state = STATE_ARROW_GRABBED_AND_PULLED; - } else { - this.updateArrowPositionInNotch(false, true); - this.updateString(); - } - } - if (this.state === STATE_ARROW_GRABBED_AND_PULLED) { - if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) { - // they unpulled without firing - this.state = STATE_ARROW_GRABBED; - } else if (this.triggerValue < DRAW_STRING_THRESHOLD) { - // they've fired the arrow - Messages.sendLocalMessage('Hifi-Hand-Disabler', "none"); - this.updateArrowPositionInNotch(true, true); - this.state = STATE_IDLE; - this.resetStringToIdlePosition(); + if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) { + // The arrow has been pulled far enough back that we can release it + Messages.sendLocalMessage('Hifi-Hand-Disabler', "none"); + this.updateArrowPositionInNotch(true, true); + this.arrow = null; + this.state = STATE_IDLE; + this.resetStringToIdlePosition(); + } else { + // The arrow has not been pulled far enough back so we just remove the arrow + Messages.sendLocalMessage('Hifi-Hand-Disabler', "none"); + Entities.deleteEntity(this.arrow); + this.arrow = null; + this.state = STATE_IDLE; + this.resetStringToIdlePosition(); + } } else { this.updateArrowPositionInNotch(false, true); this.updateString(); } } + //if (this.state === STATE_ARROW_GRABBED_AND_PULLED) { + // if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) { + // // they unpulled without firing + // this.state = STATE_ARROW_GRABBED; + // } else { + // this.updateArrowPositionInNotch(false, true); + // this.updateString(); + // } + //} }, getNotchPosition: function(bowProperties) { @@ -506,9 +510,17 @@ getControllerWorldLocation = function (handController, doOffset) { if (pullBackDistance > DRAW_STRING_MAX_DRAW) { pullBackDistance = DRAW_STRING_MAX_DRAW; } - + + var handToNotchDistance = Vec3.length(handToNotch); + var stringToNotchDistance = Math.max(0.2, Math.min(ARROW_DIMENSIONS.z - 0.1, handToNotchDistance)); var halfArrowVec = Vec3.multiply(Vec3.normalize(handToNotch), ARROW_DIMENSIONS.z / 2.0); - var arrowPosition = Vec3.sum(stringHandPosition, halfArrowVec); + var offset = Vec3.subtract(notchPosition, Vec3.multiply(Vec3.normalize(handToNotch), stringToNotchDistance - ARROW_DIMENSIONS.z / 2.0)); + if (Vec3.length(handToNotch) > 0.2) { + var arrowPosition = Vec3.subtract(notchPosition, halfArrowVec); + } else { + var arrowPosition = Vec3.sum(stringHandPosition, halfArrowVec); + } + var arrowPosition = offset; // Set arrow rear position var frontVector = Quat.getFront(arrowRotation); diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js index 67349631f4..d701466371 100644 --- a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js @@ -25,7 +25,7 @@ var userData = { } } -Entities.addEntity({ +var id = Entities.addEntity({ position: MyAvatar.position, "collisionsWillMove": 1, "compoundShapeURL": Script.resolvePath("bow_collision_hull.obj"), @@ -55,3 +55,4 @@ Entities.addEntity({ "userData": JSON.stringify(userData), lifetime: 600 }); +print("Created bow:", id);