Attaching an object to the camera's y-axis

Hi all. I wanted to snap the direction of the object to the direction of the camera (on the y-axis), but the object only followed the camera 180 degrees, then the direction was inverted. When I bind all xyz axes, then when I rotate everything works 360 degrees (I use the PointerLockControls library). Having registered the console.log(camera.rotation), I found that when the camera is rotated only along one axis, all three change, tell me how you can attach only one axis?

Pls show code / live example - it’s a bit hard to help / understand the issue with the current amount of information :eyes:

//tower8bit.scene.rotation.x=camera.rotation.x//no use
tower8bit.scene.rotation.y=camera.rotation.y//use
//tower8bit.scene.rotation.z=camera.rotation.z//no us

I think maybe try quaternion, but in this case my object is deformed

Aaaaaah - got it now.

const mock = new Three.Object3D();
const cameraDirection = new Three.Vector3();

const onFrame = () => {
  // NOTE Place mock at the same location as the object
  tower8bit.getWorldPosition(mock.position);

  // NOTE Save camera direction to a vector, then set .y component to 0.0 - so now the vector is just on the X/Z plane
  camera.getWorldDirection(cameraDirection);
  cameraDirection.y = 0.0;

  // NOTE Add position of the mock (ie. world position of the object) to the direction vector
  cameraDirection.add(mock.position);

  // NOTE Make mock look at the resulting position, ie. mock will be pointing in the same direction as the camera is, but at the y-level of the object and only on X/Z plane
  mock.lookAt(cameraDirection);
  
  // NOTE Copy the final quaternion to the original object
  tower8bit.quaternion.copy(mock.quaternion);
};
1 Like

thanks, this is what i needed