Coding a Display Carousel for 3D Objects
I have been trying to code something that looks like a circular carousel of 3D objects. A variable number of items could be evenly distributed around the circumference of a circle and would rotate along with the carousel (as if they were placed on the surface of a turntable or roulette wheel, except that they would always face the camera).
The carousel could be tilted on its x axis so the further-from-camera objects would be higher than the closer ones. If the carousel was tilted, though, the objects should still be oriented straight up.
Finally, the positions of the objects around the carousel would be able to be animated (either automatically, or in response to clockwise or counter-clockwise swipes) so that it would look like a display carousel with all the objects rotating in a circle around a center point, always facing the camera.
I started trying to do this with tweens on scene objects, but it's clear that an algorithmic solution--i.e. calculating and setting the objects' xyz positions--would be better than trying to nest a bunch of tweens.
I suspect that the "UI Carousel 3D" script in the Asset Library does 90% of what I want. It positions the objects in a straight path, so all I need to do is to change that to a circular path.
In the Carousel.js script, it's lines like these I need to learn how to change:
icon.getTransform().setLocalPosition(new vec3(i * script.margin, 0, 0)); icon.getTransform().setLocalScale(new vec3(script.scale, script.scale, script.scale)); icon.getTransform().setLocalRotation(quat.fromEulerAngles(script.eulerAngles.x, script.eulerAngles.y, script.eulerAngles.z));
I believe that instead of zeros in the last two spots of the position vec3, I also need to use some kind of trigonometry to also calculate those last two positions to make my objects appear to rotate along with the turntable in 3D-space.
Is this reasonable? Can anyone give me a pointer (since I am a mathematics bonehead) how I would calculate Y and Z also for objects and cause them to ride the turntable as it spins?