From 245fe8b7e2edc5e9c838dd02912f1613950eea10 Mon Sep 17 00:00:00 2001
From: netpro2k <netpro2k@gmail.com>
Date: Tue, 17 Jul 2018 17:25:59 -0700
Subject: [PATCH] Using offset-relative-to is actually required

---
 src/components/offset-relative-to.js |  2 ++
 src/hub.js                           | 14 +++-----------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/components/offset-relative-to.js b/src/components/offset-relative-to.js
index 23920e099..eff56e8a4 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 d98d37a05..47c1c2f61 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
       });
     };
 
-- 
GitLab