From 9ef03b120572575a06ddb10aeecbfb5677f07443 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 1 Sep 2016 19:13:08 -0700 Subject: [PATCH] avoid having auto-unequip code trigger during a teleport --- scripts/system/controllers/handControllerGrab.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 5b35245e74..ab144dcbd9 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -708,6 +708,7 @@ var equipHotspotBuddy = new EquipHotspotBuddy(); function MyController(hand) { this.hand = hand; + this.autoUnequipCounter = 0; // handPosition is where the avatar's hand appears to be, in-world. this.getHandPosition = function () { @@ -2087,6 +2088,12 @@ function MyController(hand) { var TEAR_AWAY_DISTANCE = 0.04; var nearPickedCandidateEntities = Entities.findEntities(heldItemPosition, NEAR_GRAB_RADIUS + TEAR_AWAY_DISTANCE); if (nearPickedCandidateEntities.indexOf(this.grabbedEntity) == -1) { + this.autoUnequipCounter += 1; + } else { + this.autoUnequipCounter = 0; + } + + if (this.autoUnequipCounter > 1) { // for whatever reason, the held/equipped entity has been pulled away. ungrab or unequip. print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." + props.parentID + " " + vec3toStr(props.position)); @@ -2388,6 +2395,8 @@ function MyController(hand) { }; this.activateEntity = function(entityID, grabbedProperties, wasLoaded) { + this.autoUnequipCounter = 0; + if (this.entityActivated) { return; }