Good morning, good evening, good afternoon or whatever! Hello!
Ok, so I’ve been experimenting with CFrame animation for some doors on my train. It works perfectly but there is just some mini details I want to get fixed.
At the moment, it’s too fast. However if I change the wait times it becomes “choppy” or “laggy” and not smooth. So I have to sacrifice the speed (too fast) to make it smooth.
Here’s the script:
for i = 1, 35 do
motor.C1 = motor.C1 * CFrame.new(0.007, 0, 0)
wait(0.02)
end
for i = 1, 5 do
motor.C1 = motor.C1 * CFrame.new(0, 0, -1)
wait(0.06)
end
If anyone could help that would be great! Thank you
You could use TweenService to smoothly animate your train doors, especially with the use of easing styles. It will allow smooth movement even when animating for longer durations.
Have you tried using TweenService instead? As far as I’m aware you can tween CFrame. This would also mean you get a smoother transition no matter the length. You can also negate the use of wait() by instead waiting for tweens to complete.
local tween = TweenService:Create(motor, TweenInfo.new(time), {C1 = motor.C1 *CFrame.new(0.007, 0, 0})
tween:Play()
tween.Completed:Wait() - - waits until the tween is completed
This would be a scripted example for your first cframe animation where time is the length of the tween. Of course you can customise tweeninfo for different easing styles and other properties but I’ll leave that for you to figure out.
Everyone is providing wonderful alternative methods for you to look into.
However, to answer your question directly:
You’d do more iterations and move less each time.
--This code was typed on my phone and untested
--but it worked in my head lol so fingers crossed ig
local SpeedMod = 2 --2 is ½ speed, 3 is ⅓, 4 is ¼, etc
for i = 1, 35*SpeedMod do
motor.C1 = motor.C1 * CFrame.new(0.007/SpeedMod, 0, 0)
wait(0.02)
end
for i = 1, 5*SpeedMod do
motor.C1 = motor.C1 * CFrame.new(0, 0, -1/SpeedMod)
wait(0.06)
end
Just going to warn you that if you’re tweening on the server, then your tweens are going to get choppier as time goes on. If you tween from the client, you’ll have the smoothest results.
TweenServiceV2 is a workaround for replicating tweens to make them smoother and “better”. TweenServiceV2 tweens still run on the client. It’s the same thing as not using the module and handling replication yourself.
This is true from how I understand what you’re saying. TweenServiceV2 is essentially a module to make it much easier to implement replicated tweening that only takes place on the client to save on server processing and memory buildup. If you’re tweening a core game mechanic, I would recommend creating your own replication system that works explicitly how you want it to, as TSV2 isn’t always 100% reliable in every use case.
It was really created for non-core game mechanics, especially things like movements of cosmetic objects that dont effect gameplay, and should especially not be used in situations where it’s paramount that every client sees an object in the exact same position, to the 100th of a stud, at one time. (The main example of this is objects in a competitive game, like a shooter or obstacle course as objects not being 100% synced may give some players an unfair advantage.)