diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index cf9b245993..ed02bd3709 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1234,39 +1234,16 @@ function MyController(hand) { this.handleSpotlight(this.grabbedEntity); } - var success = Entities.updateAction(this.grabbedEntity, this.actionID, { + Entities.updateAction(this.grabbedEntity, this.actionID, { targetPosition: targetPosition, linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, targetRotation: this.currentObjectRotation, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, ttl: ACTION_TTL }); - if (success) { - this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); - } else { - print("continueDistanceHolding -- updateAction failed"); - } - }; - - this.setupHoldAction = function() { - this.actionID = Entities.addAction("hold", this.grabbedEntity, { - hand: this.hand === RIGHT_HAND ? "right" : "left", - timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, - relativePosition: this.offsetPosition, - relativeRotation: this.offsetRotation, - ttl: ACTION_TTL, - kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: true, - ignoreIK: this.ignoreIK - }); - if (this.actionID === NULL_ACTION_ID) { - this.actionID = null; - return false; - } - var now = Date.now(); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); - return true; + }; this.projectVectorAlongAxis = function(position, axisStart, axisEnd) { @@ -1296,7 +1273,7 @@ function MyController(hand) { return projection - }; + }, this.nearGrabbing = function() { var now = Date.now(); @@ -1340,29 +1317,43 @@ function MyController(hand) { this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset); } - if (!this.setupHoldAction()) { - return; - } - - if (this.state == STATE_NEAR_GRABBING) { - this.setState(STATE_CONTINUE_NEAR_GRABBING); + this.actionID = NULL_ACTION_ID; + this.actionID = Entities.addAction("hold", this.grabbedEntity, { + hand: this.hand === RIGHT_HAND ? "right" : "left", + timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, + relativePosition: this.offsetPosition, + relativeRotation: this.offsetRotation, + ttl: ACTION_TTL, + kinematic: NEAR_GRABBING_KINEMATIC, + kinematicSetVelocity: true, + ignoreIK: this.ignoreIK + }); + if (this.actionID === NULL_ACTION_ID) { + this.actionID = null; } else { - // equipping - Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]); - this.startHandGrasp(); + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); + if (this.state == STATE_NEAR_GRABBING) { + this.setState(STATE_CONTINUE_NEAR_GRABBING); + } else { + // equipping + Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]); + this.startHandGrasp(); + + this.setState(STATE_CONTINUE_EQUIP_BD); + } + + if (this.hand === RIGHT_HAND) { + Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); + } else { + Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); + } + + Entities.callEntityMethod(this.grabbedEntity, "setHand", [this.hand]); + + Entities.callEntityMethod(this.grabbedEntity, "startNearGrab"); - this.setState(STATE_CONTINUE_EQUIP_BD); } - if (this.hand === RIGHT_HAND) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } - - Entities.callEntityMethod(this.grabbedEntity, "setHand", [this.hand]); - Entities.callEntityMethod(this.grabbedEntity, "startNearGrab"); - this.currentHandControllerTipPosition = (this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition; @@ -1412,7 +1403,7 @@ function MyController(hand) { if (this.actionTimeout - now < ACTION_TTL_REFRESH * MSEC_PER_SEC) { // if less than a 5 seconds left, refresh the actions ttl - var success = Entities.updateAction(this.grabbedEntity, this.actionID, { + Entities.updateAction(this.grabbedEntity, this.actionID, { hand: this.hand === RIGHT_HAND ? "right" : "left", timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, relativePosition: this.offsetPosition, @@ -1422,13 +1413,7 @@ function MyController(hand) { kinematicSetVelocity: true, ignoreIK: this.ignoreIK }); - if (success) { - this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); - } else { - print("continueNearGrabbing -- updateAction failed"); - Entities.deleteAction(this.grabbedEntity, this.actionID); - this.setupHoldAction(); - } + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); } }; @@ -1475,7 +1460,7 @@ function MyController(hand) { return; } } else { - var success = Entities.updateAction(this.grabbedEntity, this.equipSpringID, { + Entities.updateAction(this.grabbedEntity, this.equipSpringID, { targetPosition: targetPosition, linearTimeScale: EQUIP_SPRING_TIMEFRAME, targetRotation: targetRotation, @@ -1483,9 +1468,6 @@ function MyController(hand) { ttl: ACTION_TTL, ignoreIK: ignoreIK }); - if (!success) { - print("pullTowardEquipPosition -- updateActionfailed"); - } } if (Vec3.distance(grabbedProperties.position, targetPosition) < EQUIP_SPRING_SHUTOFF_DISTANCE) { @@ -1867,4 +1849,4 @@ function cleanup() { } Script.scriptEnding.connect(cleanup); -Script.update.connect(update); +Script.update.connect(update); \ No newline at end of file