diff --git a/src/components/offset-relative-to.js b/src/components/offset-relative-to.js index 23920e099a94fd50373f6804bf8c02d8cae0910f..eff56e8a45e9f201bbabbbf516de4a3625e843dc 100644 --- a/src/components/offset-relative-to.js +++ b/src/components/offset-relative-to.js @@ -37,10 +37,12 @@ AFRAME.registerComponent("offset-relative-to", { obj.parent.worldToLocal(offsetVector); } obj.position.copy(offsetVector); + this.el.body && this.el.body.position.copy(obj.position); // TODO: Hack here to deal with the fact that the rotation component mutates ordering, and we network rotation without sending ordering information // See https://github.com/networked-aframe/networked-aframe/issues/134 obj.rotation.order = "YXZ"; target.getWorldQuaternion(obj.quaternion); + this.el.body && this.el.body.quaternion.copy(obj.quaternion); if (this.data.selfDestruct) { if (this.data.on) { this.el.sceneEl.removeEventListener(this.data.on, this.updateOffset); diff --git a/src/hub.js b/src/hub.js index d98d37a054937eaee6a8b61dc63848a4f30680ac..47c1c2f616677e890c7d471d0d20bfdd4a3a51bd 100644 --- a/src/hub.js +++ b/src/hub.js @@ -305,19 +305,11 @@ const onReady = async () => { }); const offset = { x: 0, y: 0, z: -1.5 }; - const playerCamera = document.querySelector("#player-camera").object3D; - const spawnPos = new THREE.Vector3(); - const spawnRot = new THREE.Quaternion(); const spawnMediaInfrontOfPlayer = url => { const entity = addMedia(url, true); - entity.addEventListener("loaded", () => { - console.log("body loaded"); - spawnPos.copy(offset); - playerCamera.localToWorld(spawnPos); - playerCamera.getWorldQuaternion(spawnRot); - console.log(spawnPos, spawnRot); - entity.body.position.copy(spawnPos); - entity.body.quaternion.copy(spawnRot); + entity.setAttribute("offset-relative-to", { + target: "#player-camera", + offset }); };