Skip to content

How to only sync one axis of an object’s rotation? #404

Discussion options

You must be logged in to vote

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:

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">
  <

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vincentfretin
Comment options

Answer selected by vincentfretin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant