From c98685f6d390d7d6e1f2d09a3b3fae60c6a0673b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 16 Oct 2015 11:39:27 -0700 Subject: [PATCH] in STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING, when the ray moves off of the entity, switch back to search state --- examples/controllers/handControllerGrab.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index c607946f2f..faa90efdff 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -579,9 +579,7 @@ function MyController(hand, triggerAction) { Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); } Entities.callEntityMethod(this.grabbedEntity, "startFarGrabNonColliding"); - // TODO -- figure out how to make this work. - // this.setState(STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING); - this.setState(STATE_RELEASE); + this.setState(STATE_CONTINUE_FAR_GRABBING_NON_COLLIDING); }; this.continueNearGrabbingNonColliding = function() { @@ -589,7 +587,7 @@ function MyController(hand, triggerAction) { this.setState(STATE_RELEASE); return; } - + Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding"); }; @@ -605,6 +603,16 @@ function MyController(hand, triggerAction) { direction: Quat.getUp(this.getHandRotation()) }; + var now = Date.now(); + if (now - this.lastPickTime > MSECS_PER_SEC / PICKS_PER_SECOND_PER_HAND) { + var intersection = Entities.findRayIntersection(pickRay, true); + this.lastPickTime = now; + if (intersection.entityID != this.grabbedEntity) { + this.setState(STATE_RELEASE); + return; + } + } + this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); Entities.callEntityMethod(this.grabbedEntity, "continueFarGrabbingNonColliding"); };