Skip to content
Snippets Groups Projects
Commit 7d10203a authored by netpro2k's avatar netpro2k
Browse files

Have sticky zone boot out previously stuck object

parent 2b61513f
No related branches found
No related tags found
No related merge requests found
...@@ -54,20 +54,47 @@ AFRAME.registerComponent("sticky-object", { ...@@ -54,20 +54,47 @@ AFRAME.registerComponent("sticky-object", {
AFRAME.registerComponent("sticky-object-zone", { AFRAME.registerComponent("sticky-object-zone", {
dependencies: ["physics"], dependencies: ["physics"],
init() { init() {
const q = new THREE.Quaternion(); // TODO: position/rotation/impulse need to get updated if the sticky-object-zone moves
const p = new THREE.Vector3(); this.worldQuaternion = new THREE.Quaternion();
this.el.object3D.getWorldQuaternion(q); this.worldPosition = new THREE.Vector3();
this.el.object3D.getWorldPosition(p); this.el.object3D.getWorldQuaternion(this.worldQuaternion);
this.el.object3D.getWorldPosition(this.worldPosition);
const dir = new THREE.Vector3(0, 0, 5).applyQuaternion(this.el.object3D.quaternion);
this.bootImpulsePosition = new CANNON.Vec3(0, 0, 0);
this.bootImpulse = new CANNON.Vec3();
this.bootImpulse.copy(dir);
this.el.addEventListener("collisions", e => { this.el.addEventListener("collisions", e => {
console.log("collisions", e.detail.els, e.detail.clearedEls); console.log("collisions", e.detail.els, e.detail.clearedEls);
e.detail.els.forEach(el => { e.detail.els.forEach(el => {
const stickyObject = el.components["sticky-object"]; const stickyObject = el.components["sticky-object"];
if (!stickyObject) return; if (!stickyObject) return;
this._setStuckObject(stickyObject);
stickyObject.setLocked(true);
el.object3D.position.copy(p);
el.object3D.quaternion.copy(q);
}); });
if (this.stuckObject) {
e.detail.clearedEls.forEach(el => {
if (this.stuckObject && this.stuckObject.el === el) {
delete this.stuckObject;
}
});
}
}); });
},
_setStuckObject(stickyObject) {
stickyObject.setLocked(true);
stickyObject.el.object3D.position.copy(this.worldPosition);
stickyObject.el.object3D.quaternion.copy(this.worldQuaternion);
stickyObject.el.body.collisionResponse = false;
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.stuckObject.el.body.applyImpulse(this.bootImpulse, this.bootImpulsePosition);
}
this.stuckObject = stickyObject;
} }
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment