diff --git a/src/components/sticky-object.js b/src/components/sticky-object.js index 99f93ffafcfcfb2c8e7ff4045d4ac4e758663daa..933754ac6bec95d6915a743fec70f6cfac7be3b4 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; } });