Hi, I’m currently trying to make a system where each time an object completes a full rotation (360 Degree Spin) on with a HingeConstraint motor, a function gets ran. It needs to be able to calculate the time based on the fact that:
The AngularVelocity is variable
The MotorMaxAcceleration and MotorMaxTorque is inf
I am completely lost on how to do this, or if it’s possible. I assume it’d have to do something with the size of the model and the AngularVelocity but I’m not sure.
I’m not sure how helpful this is going to be, or if it’s even the best method but,
local runService = game:GetService('RunService')
local part = workspace.Part
local initY = part.Orientation.Y -- switch if you have a different axis
local initTick = tick()
runService.Heartbeat:Wait()
local time = tick() - initTick
local diff = part.Orientation.Y - initY -- switch if you have a different axis
local timeToRotate = 360 / (diff / time)
The timeToRotate variable should give you an estimate for how long it takes to do a full rotation
Yeah this didn’t work for me. This is how I implemented it:
local InitialY = Model.Motor.Orientation.Y
local InitialTick = tick()
--// the model starts spinning after this
RunService.Heartbeat:Wait()
local Time = tick() - InitialTick
local Difference = Model.Motor.Orientation.Y
local TimeToRotate = (360 / (Difference / Time))
while Spinning do
task.wait(TimeToRotate)
if Settings.OnSpinCompleted then
Settings.OnSpinCompleted(Model)
end
end
The main reason its not working at all is probably because you forgot to subtract the initialY from the difference
Also:
Is the change of the speed at which the motor rotates predictable in any way?
Theres not really a way to accurately predict how long it will take with any actual accuracy
Itd probably be like those bad “x seconds to download” counters which dont work at all when downloading something
Your best bet would just waiting until the motors angle has rotated 360 or more degrees from the start if you cant predict how it will change, or at the very least updating the time every heartbeat or something