How to only sync one axis of an object’s rotation? #404
Answered
by
vincentfretin
vincentfretin
asked this question in
Q&A
-
Question asked by Ben Weekes on slack: |
Beta Was this translation helpful? Give feedback.
Answered by
vincentfretin
Mar 31, 2023
Replies: 1 comment 1 reply
-
What I do for this use case is creating a component AFRAME.registerComponent("rotation-y-only", {
init: function () {
this.camera = this.el.querySelector(".camera");
this.camera.object3D.rotation.order = "YXZ";
this.model = this.el.querySelector(".model");
this.model.object3D.rotation.order = "YXZ";
},
tick: function () {
const cameraRot = this.camera.object3D.rotation;
this.model.object3D.rotation.set(0, cameraRot.y + Math.PI, 0);
},
}); <template id="avatar-template">
<a-entity player-info>
<a-entity class="model" gltf-model="some.glb"></a-entity>
<a-entity class="camera" networked-audio-source></a-entity>
</a-entity>
</template> <a-entity
id="cameraRig"
rotation-y-only
networked="template:#avatar-template;attachTemplateToLocal:false;"
>
<a-entity
id="camera"
class="camera"
camera
look-controls=""
position="0 1.6 0"
></a-entity>
<a-entity class="model" gltf-model="some.glb"></a-entity>
</a-entity> NAF.schemas.add({
template: "#avatar-template",
components: [
"player-info",
{
component: "position",
requiresNetworkUpdate: NAF.utils.vectorRequiresUpdate(0.001),
},
{
component: "rotation",
requiresNetworkUpdate: NAF.utils.vectorRequiresUpdate(0.5),
},
{
selector: ".model",
component: "rotation",
requiresNetworkUpdate: NAF.utils.vectorRequiresUpdate(0.5),
},
],
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
vincentfretin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What I do for this use case is creating a component
rotation-y-only
that copy the rotation y of the camera to another entity that have the model and I sync the model rotation in the networked schema.Here are the different parts of the code: