Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this camera spin script stop at the correct rotations? (Challenging!)

Asked by
RoboFrog 400 Moderation Voter
9 years ago

I've got an intro script that spins around and such, and when clicked, does a few pre-determined spins to certain locations. As of now, if left running for long enough, it'll slowly start to stop in incorrect positions. Here's the script snippet:

        repeat wait()
        angle = angle + math.rad(2) 
        anglech = (math.floor(angle+0.25))
        camera.CoordinateFrame = CFrame.new(targetst.Position) * CFrame.Angles(0, angle, 0)
        print(anglech)
        until (anglech % 5 == 0) 

        repeat wait()
        angle = angle + math.rad(1.5)
        anglech = (math.floor(angle+0.25))
        camera.CoordinateFrame = CFrame.new(targetst.Position) * CFrame.Angles(0, angle, 0)
        print(anglech)
        until (anglech % 6 == 0) 

As I've learned, rotation with this camera goes in intervals of 6 when it comes to the difference. Therefore, 6 == 12 in terms of where the camera is facing. EDIT: This is actually most likely incorrect.

% is Modulo (in case it's not known), which is the remainder after division.

However, an issue comes up when, for instance, it gets to 35. That isn't in the 5th position still, but is still divisible by 5. Therefore, the camera stops prematurely, then doesn't finish the second loop correctly either.

So, my question is, how could I modify the until algorithm to stop at the correct rotations?

Thank you for reading, and I hope to find the solution soon!

Answer this question