Free spinning on one axis then snapping to nearest 36 degrees

Hey there,

My problem is simple in theory. If you consider a combo lock with spinners you can freely spin the numbers. The difference with my problem is when you stop spinning the numbers I would like it to automatically snap to the nearest number/side flush.

I have a decagon who’s sides line up with the camera every 36 degrees on the z-axis.
I can freely rotating it using .Rotate. When I stop rotating it I would like to code to look at its current rotation and determine where the nearest 36 degree angle is and snap to it so that it is flush with the camera again.

I’ve looked everywhere and I’ve found similar questions but not quite the same. I hate quaternions.

I would appreciate any insight. Thanks!

You could use the accepted solution to:

In your case probably:

    vector3 vec = transform.eulerAngles;
    vec.z = Mathf.Round(vec.z / 36) * 36;
    transform.eulerAngles = vec;

The part that calculates this angle in relation to the camera’s angle would be a bit more tricky and depends a lot on where the camera is at any given moment (dunno if you need that part).