[SOLVED] Auto Rotate Object

Hi all

I stumbled across this example, which is great

What i’d like to achieve is the auto-rotation of the object (Only on X/Y axis),
without touching the camera (we need a fixed skybox in order to mantain certain reflections)

Can you please help?

Not entirely sure what you are asking here as it sounds like you just want to rotate the object.

Is this what you are looking for? https://playcanvas.com/project/586330/overview/the-room-item-exam

Hi Yaustar,
Thanks for the sample, it’s very similar to what we’d like to achieve.

Basically our idea is to have an auto-rotation of the object, while mantaining a fixed skybox.

  • The object should rotate atomatically after 2s of user inactivity
    (when there’s user activity, we move the model accordingly)
  • The X rotation is clamped between +90/-90°
  • No limit on Y rotation
  • No Z rotation at all

To be more clear, we prepared a sample project, you can find it here

(relevant code is in camera-controller.js file)

It kind of works but, if you play with it for a while, you’ll notice that yaw starts to behave funny,
the model gets some “trembling effect” while repositioning or the model gets stuck

Any help is appreciated

Hi @Change2,

I gave your project a try, seems to be working, I am not sure I am seeing any trembling or the model getting stuck.

Is this what you are seeing? If you find movements to be to rough, you can smooth them out by increasing the inertia (your lerping times).

Hi @Leonidas, thanks for checking it out.

I’ll send you a video of what i mean, this happens sometimes, after a bit of rotations/plays

So we found out where the problem was…

The rotation code itself was okay but the mouse/touch/cam-controller scripts
were using local non-shared variables to store the object current angles.

This was causing conflicts while the app was running, the more the user interacted with the scene,
the messier and unstable the animation become.

We’re leaving the solution here, the code could probably be better, but maybe it can help someone in the future