Hello everyone! I’d like an idea of how i could turn the given time on os.date into things like radians / angles, to put into a Clock Model like this one:
My first thought was to use radians / angles like mentioned above, but if there is any other ideas that could be better, i would appreciate it if you shared them + some way of how i could implement them.
Any other functions / ways to get the Time other than os.date could also be used, but i only know of os.date
How could i achieve such a thing?
Thanks for the read.
You could propagate some formulas to move to hand for each unit of time and move the clock with radians. Ill list some here (Assuming you know how to access each unit already). Some info first
– There are 6.28 radians in one full circle
– Use 12 hr clock
Now you can implement these formulas to change the hands of your clock. For example: workspace.Clock.Hands.HourHand.CFrame *= CFrame.Angles(0,0,Hours) -- Could be X or Z axis, change in lieu to situation
local ClockModel = workspace.Plate.Clock
local function ChangeClockHourHand()
local HourHand = ClockModel.HourHand
local HourAngle = (os.date("%I") / 12) / 6.28
print(HourAngle)
HourHand.CFrame *= CFrame.Angles(math.rad(HourAngle),0,0)
end
local function ChangeClockMinutesHand()
local MinutesHand = ClockModel.MinutesHand
local MinutesAngle = (os.date("%M") / 60) / 6.28
print(MinutesAngle)
MinutesHand.CFrame *= CFrame.Angles(math.rad(MinutesAngle),0,0)
end
ChangeClockMinutesHand()
ChangeClockHourHand()
Output:
My thoughts initially is to divide the numbers by a lesser amount.
The larger hand is the Minute Hand and it is moving. If there was a second hand then it would probably be moving faster (You could add a second hand if you want). The entire minute hand is also moving in the opposite direction (simple fix, multiply -CFrame.angles) which is not how it’s supposed to be. I’m thinking add a cylindrical/ ball socket constraint to like fix the minute hand to the centre, but experiment however you want
Hey Im working on this with him and now Im experiencing an issue where the hour hand and minutes hand is not showing the time correctly and they seem to be moving a bit fast. I changed it to use pivotTo since i made it into a model to have a guide within the model in order to guide the hands if that makes sense.
Hi there, sorry for the inconvenience I caused with my solution up there
Let me explain:
For every minute/hour that passes, the Minutes angle increases. The reason it’s moving faster and faster (I’m deducing this) is because the angle you’re multiplying with increases, so the speed actually increases constantly, making the solution wrong. Try this code instead (example for minute hand). It does switch from radians to degrees but as long as it works I hope you will find it helpful
local MinutesAngle = (os.date(%M) / 60) -- [[Get the amount you need to move as a
fraction of the total minutes e.g. 30/60 = 1/2, so the hand needs to be halfway across the clock.
print(MinutesAngle)
MinutesHand.Rotation = Vector3.new(math.rad(MinutesAngle * 360),0,0) --[[Now we get the
number of degrees the hand has to move by multiplying the MinutesAngle (rmb that its a fraction) by 360
degrees (degrees in a full circle)
This is refined from my ‘solution’ up there as it sets a new rotation every time the MinutesAngle fraction changes instead of multiplying a larger fraction than before. This should also be accurate as the fraction is represented by the os.date() data. Feel free to clear up your doubts with me
I have tried to use your method on the minutes hand and the hand seems to visually spinning vertically in angles of 45* i dont know its hard to describe but somethings not right.
heres my code:
local function ChangeClockHourHand()
local HourHand = ClockModel.Hour
local HourAngle = (os.date("%I") / 12) / 6.28
HourHand:PivotTo(HourHand.WorldPivot * CFrame.Angles(0,math.rad(HourAngle),0))
end
local function ChangeClockMinutesHand()
local MinutesHand = ClockModel.Minutes
local MinutesAngle = (os.date("%M") / 60)
MinutesHand:PivotTo(MinutesHand.Guide.CFrame * CFrame.Angles(math.rad(MinutesAngle * 360),0,0))
ChangeClockHourHand()
end
while task.wait(0.1) do
ChangeClockMinutesHand()
end
You could attach a video for me to see, but I see some errors already
Do not use :PivotTo(), use MinutesHand.Rotation as it’s only the rotation that you want to change and not anything else
Also, Do not multiply with CFrame.Angles(), you have to set a new rotation as the fraction only gets larger as time passes and thus the degrees you are translating it by increases. Here’s the updated code:
local function ChangeClockHourHand()
local HourHand = ClockModel.Hour
local HourAngle = (os.date("%I") / 12)
HourHand.Rotation = Vector3.new(math.rad(HourAngle * 360),0,0)
end
local function ChangeClockMinutesHand()
local MinutesHand = ClockModel.Minutes
local MinutesAngle = (os.date("%M") / 60)
HourHand.Rotation = Vector3.new(math.rad(HourAngle * 360),0,0)
ChangeClockHourHand()
end
while task.wait(0.1) do
ChangeClockMinutesHand()
end
it just does this when i playtest and the hour hand moves I also don’t know how to make the hands move from the centre without being the diameter of the clock