Rotate 3D object on button press

Hi there,

Am trying to get a 3D model to rotate along the Y-axis as a button is pressed (or a user swipes left/right) but am unable to find a solution.

The photo sphere feature isn’t quite right, as the 3D model is locked to a tracking image, and needs to stay in it’s place, rather than be completely scalable/moveable?

I’m looking for a way to update on the Y rotation, so that when a button is pressed/held, it rotates left/right from it’s current rotation.

Many thanks
Adam

Hi Adam,
I think a simple way to do that is to create a timeline of your object rotating 360° on the Y axis with the loop checkbox on. Then, on your button, just add 2 scripts, one on the pointerdown() event to start the animation the other on the pointerup() event to stop it (In fact, I should recommend to add the stop also on the pointerleave event) .
Jean.

1 Like

Oh, I forgot to mention to use the speed rate to reverse the rotation: youranimation.play(-1)
Jean.

Hi Jean,

Thanks so much for taking the time to reply. Much appreciated, and thank you for the tip.

Do you know of any way this rotation would be possible with code? We have a series of 12 character models that we need to apply this too, so 12 animated renders of the spin might be quite time consuming. If there was a way to rotate along the Y axis with a button click, or a screen drag, that would be a lot easier for us.

Thanks again,
Adam

By code, you can use the rotation() function: yourObject.rotation([0,yourAngle++,0]);
For a continuous rotation, the instruction above should be in a function called by a Z.every(…) function on the pointerenter event and stopped by a Z.everyOff(…) on the pointerleave event.

But if you want to use the drag, there is a thread here:

Hi again Jean,

Thank you so much for your reply, that has worked perfectly!

Really appreciate the time and the detailed instructions to get it there.

Cheers
Adam

1 Like

Glad it helped! :slight_smile:

1 Like