History

Merge pull request #11838 from druiz17/fix-grabbing

fixing setting incorrect parent when grabbing entities

Brad Hefta-Gaub committed 8 years ago

Commit 068b93f2 parents 56e299c 56972d11 file · +21 −1Browse files

Showing the changes to scripts/system/controllers/controllerModules (1 of 1 file). Show all

Unified · Split

scripts/system/controllers/controllerModules/nearParentGrabEntity.js+21−1
@@ -33,6 +33,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 32 unmodified lines
3333 this.lastUnequipCheckTime = 0;
3434 this.autoUnequipCounter = 0;
3535 this.lastUnexpectedChildrenCheckTime = 0;
36+ this.robbed = false;
3637
3738 this.parameters = makeDispatcherModuleParameters(
3839 500,
@@ -75,6 +76,14 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 36 unmodified lines
7576 return false;
7677 };
7778
79+ this.getOtherModule = function() {
80+ return this.hand === RIGHT_HAND ? leftNearParentingGrabEntity : rightNearParentingGrabEntity;
81+ };
82+
83+ this.otherHandIsParent = function(props) {
84+ return this.getOtherModule().thisHandIsParent(props);
85+ };
86+
7887 this.startNearParentingGrabEntity = function (controllerData, targetProps) {
7988 Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
8089
@@ -100,6 +109,11 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 19 unmodified lines
100109 // this should never happen, but if it does, don't set previous parent to be this hand.
101110 this.previousParentID[targetProps.id] = null;
102111 this.previousParentJointIndex[targetProps.id] = -1;
112+ } else if (this.otherHandIsParent(targetProps)) {
113+ var otherModule = this.getOtherModule();
114+ this.previousParentID[this.grabbedThingID] = otherModule.previousParentID[this.grabbedThingID];
115+ this.previousParentJointIndex[this.grabbedThingID] = otherModule.previousParentJointIndex[this.grabbedThingID];
116+ otherModule.robbed = true;
103117 } else {
104118 this.previousParentID[targetProps.id] = targetProps.parentID;
105119 this.previousParentJointIndex[targetProps.id] = targetProps.parentJointIndex;
@@ -119,7 +133,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 13 unmodified lines
119133 this.endNearParentingGrabEntity = function (controllerData) {
120134 this.hapticTargetID = null;
121135 var props = controllerData.nearbyEntityPropertiesByID[this.targetEntityID];
122− if (this.thisHandIsParent(props)) {
136+ if (this.thisHandIsParent(props) && !this.robbed) {
123137 if (this.previousParentID[this.targetEntityID] === Uuid.NULL || this.previousParentID === undefined) {
124138 Entities.editEntity(this.targetEntityID, {
125139 parentID: this.previousParentID[this.targetEntityID],
@@ -145,6 +159,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 19 unmodified lines
145159 }));
146160 this.grabbing = false;
147161 this.targetEntityID = null;
162+ this.robbed = false;
148163 };
149164
150165 this.checkForChildTooFarAway = function (controllerData) {
@@ -253,12 +268,14 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 102 unmodified lines
253268 if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE &&
254269 controllerData.secondaryValues[this.hand] < TRIGGER_OFF_VALUE) {
255270 this.checkForUnexpectedChildren(controllerData);
271+ this.robbed = false;
256272 return makeRunningValues(false, [], []);
257273 }
258274
259275 if (targetProps) {
260276 if ((propsArePhysical(targetProps) || propsAreCloneDynamic(targetProps)) &&
261277 targetProps.parentID === Uuid.NULL) {
278+ this.robbed = false;
262279 return makeRunningValues(false, [], []); // let nearActionGrabEntity handle it
263280 } else {
264281 this.targetEntityID = targetProps.id;
@@ -266,6 +283,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 1 unmodified line
266283 }
267284 } else {
268285 this.hapticTargetID = null;
286+ this.robbed = false;
269287 return makeRunningValues(false, [], []);
270288 }
271289 };
@@ -284,6 +302,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 12 unmodified lines
284302 this.grabbing = false;
285303 this.targetEntityID = null;
286304 this.hapticTargetID = null;
305+ this.robbed = false;
287306 return makeRunningValues(false, [], []);
288307 }
289308
@@ -300,6 +319,7 @@ Script.include("/~/system/libraries/cloneEntityUtils.js"); · 10 unmodified lines
300319 // still searching / highlighting
301320 var readiness = this.isReady(controllerData);
302321 if (!readiness.active) {
322+ this.robbed = false;
303323 return readiness;
304324 }
305325 if (controllerData.triggerClicks[this.hand] || controllerData.secondaryValues[this.hand] > BUMPER_ON_VALUE) {