From a1ffc7abd01cc59a848310aa450e8634a9d5983c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 8 Sep 2017 17:04:09 -0700 Subject: [PATCH] distance from controller to object is sometimes decided by pickray --- scripts/system/controllers/controllerDispatcher.js | 6 +++--- .../controllers/controllerModules/nearActionGrabEntity.js | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/system/controllers/controllerDispatcher.js b/scripts/system/controllers/controllerDispatcher.js index 759d9c8f31..c52b3d56df 100644 --- a/scripts/system/controllers/controllerDispatcher.js +++ b/scripts/system/controllers/controllerDispatcher.js @@ -205,6 +205,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var entityID = nearbyEntityIDs[j]; var props = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES); props.id = entityID; + props.distance = Vec3.distance(props.position, controllerLocations[h].position) nearbyEntityPropertiesByID[entityID] = props; nearbyEntityProperties[h].push(props); } @@ -236,6 +237,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); var nearEntityID = rayPicks[h].objectID; var nearbyProps = Entities.getEntityProperties(nearEntityID, DISPATCHER_PROPERTIES); nearbyProps.id = nearEntityID; + nearbyProps.distance = rayPicks[h].distance; nearbyEntityPropertiesByID[nearEntityID] = nearbyProps; nearbyEntityProperties[h].push(nearbyProps); } @@ -243,9 +245,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); // sort by distance from each hand nearbyEntityProperties[h].sort(function (a, b) { - var aDistance = Vec3.distance(a.position, controllerLocations[h].position); - var bDistance = Vec3.distance(b.position, controllerLocations[h].position); - return aDistance - bDistance; + return a.distance - b.distance; }); } diff --git a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js index 932cbda179..d76de2b428 100644 --- a/scripts/system/controllers/controllerModules/nearActionGrabEntity.js +++ b/scripts/system/controllers/controllerModules/nearActionGrabEntity.js @@ -148,8 +148,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); for (var i = 0; i < nearbyEntityProperties.length; i++) { var props = nearbyEntityProperties[i]; var handPosition = controllerData.controllerLocations[this.hand].position; - var distance = Vec3.distance(props.position, handPosition); - if (distance > NEAR_GRAB_RADIUS) { + if (props.distance > NEAR_GRAB_RADIUS) { break; } if (entityIsGrabbable(props)) {