From bbb12601206ec1282adffcc1f762c45bd612f933 Mon Sep 17 00:00:00 2001 From: netpro2k <netpro2k@gmail.com> Date: Thu, 21 Jun 2018 13:59:06 -0700 Subject: [PATCH] Fix issue with objects falling through the floor after entering a sticky zone --- src/components/sticky-object.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/components/sticky-object.js b/src/components/sticky-object.js index 99f93ffaf..933754ac6 100644 --- a/src/components/sticky-object.js +++ b/src/components/sticky-object.js @@ -37,12 +37,9 @@ AFRAME.registerComponent("sticky-object", { }, setLocked(locked) { - if (!NAF.utils.isMine(this.el)) { - console.log("Object not mine, ignoring setting locked: ", locked); - return; - } + if (!NAF.utils.isMine(this.el)) return; + const mass = this.el.components["super-networked-interactable"].data.mass; - console.log("setting locked", locked, mass); this.locked = locked; this.el.body.type = locked ? window.CANNON.Body.STATIC : window.CANNON.Body.DYNAMIC; this.el.setAttribute("body", { @@ -85,7 +82,6 @@ AFRAME.registerComponent("sticky-object-zone", { this.bootImpulse.copy(dir); this.el.addEventListener("collisions", e => { - console.log("collisions", e.detail.els, e.detail.clearedEls); e.detail.els.forEach(el => { const stickyObject = el.components["sticky-object"]; if (!stickyObject) return; @@ -94,6 +90,10 @@ AFRAME.registerComponent("sticky-object-zone", { if (this.stuckObject) { e.detail.clearedEls.forEach(el => { if (this.stuckObject && this.stuckObject.el === el) { + // this condition will be false when dragging an object directly from one sticky zone to another + if (this.stuckObject.stuckTo === this) { + this._unstickObject(); + } delete this.stuckObject; } }); @@ -106,14 +106,19 @@ AFRAME.registerComponent("sticky-object-zone", { stickyObject.el.object3D.position.copy(this.worldPosition); stickyObject.el.object3D.quaternion.copy(this.worldQuaternion); stickyObject.el.body.collisionResponse = false; + stickyObject.stuckTo = this; if (this.stuckObject && NAF.utils.isMine(this.stuckObject.el)) { - console.log("booting out object"); - this.stuckObject.setLocked(false); - this.stuckObject.el.body.collisionResponse = true; + this._unstickObject(); this.stuckObject.el.body.applyImpulse(this.bootImpulse, this.bootImpulsePosition); } this.stuckObject = stickyObject; + }, + + _unstickObject() { + this.stuckObject.setLocked(false); + this.stuckObject.el.body.collisionResponse = true; + delete this.stuckObject.stuckTo; } }); -- GitLab