Local axis object rotation

I want to rotate an object on its Y axis after having rotated it on its Z axis.

In Blender I can do this by changing the rotation order from XYZ to ZXY, but in Threejs I don’t know how to do it. I have imported the object to scene. This is its initial state without rotation:

Captura de pantalla 2023-12-11 a las 11.24.17

This is the rotation if I modify the X axis first and then the Y axis. It works:

  useEffect(() => {
    model.current.rotation.x = 1;
  }, []);

  useFrame((state, delta) => {
    model.current.rotation.y += delta;
  });

Grabación de pantalla 2023-12-11 a las 11.05.03

But if I modify the Z first and then the Y (which is what I need to do), it doesn’t work:

  useEffect(() => {
    model.current.rotation.z = 1;
  }, []);

  useFrame((state, delta) => {
    model.current.rotation.y += delta;
  });

Grabación de pantalla 2023-12-11 a las 11.47.22

Y rotation takes the global Y axis, not local. It seems different behavior than previous example.

This is the entire app code

How can I get this rotation?

You can use object.rotateY(delta);

2 Likes

What easy! It works. Thanks.