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

Is there a better, smoother way to rotate objects?

Asked by 6 years ago

Okay, so normally if i'd want something to continually rotate, I would use something like

for i = 1,15 do
    object.CFrame = Object.CFrame *CFrame.Angles(0.1,0,0)
    wait(.1)
end

What i'm wondering is, is there a way outside of this method to make something rotate? This way gets the job done but I feel as though it's really choppy and not smooth at all.

1
I know there is a tween for objects and Vector3.new greatneil80 2647 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Options:

  • Use wait(), which will wait for approximately 0.03 seconds (this will update 3x more frequently than what you are currently doing)
  • Use RunService's events/functions to update the animation. This is up to 2x better than the previous option, but it's sometimes harder to script (specifically to start and stop it when you want) and isn't that noticeable. ex:
game:GetService("RunService").Heartbeat:Connect(function(step)
    object.CFrame = object.CFrame * CFrame.Angles(0.02,0,0)
end)

You can also improve the animation quality by doing rotation based on the amount of time that has elapsed. ex, wait() actually returns this, and you can use the step argument for the same purpose. ex, instead of doing * CFrame.Angles(0.02, 0, 0), you might just do * CFrame.Angles(step, 0, 0). This way, if the game slows down or lags, the animation will still continue at the same speed (though obviously choppier).

[Edit: greatneil80 is right, you can also use the TweenService to rotate, though you'd have to update it pretty much every frame if you wanted something to rotate indefinitely. Still, you could combine it with the wait() for loop if you wanted to avoid using the RunService.]

Ad

Answer this question