I thought I’d ask if anyone has a neat ready-made solution:
What’s the simplest way to implement a 24hr clock, showing hours and minutes. It doesn’t need to be in real time, just needs its rate to be set by a Speed variable.
I’m not good at math and all my tentative solutions involve too many variables.
forgot to mention - it needs to be synced to the rotation of a planet - 360 degrees = 24hrs.
here ya go
usage:
on your clock, with the various hands,
function
var fu: Time;
var Planet: Transform;
var HourHand: Transform;
var minutehand: Transform;
var secondhand: Transform;
fu.zeroHourDegrees=Planet.eulerAngles.y;
function LateUpdate()
{
fu.SetTime(Planet.eulerAngles.y);
secondhand.eulerAngles=Vector3(0,fu.GetHours(),0);
secondhand.eulerAngles.y=Vector3(0,fu.GetMinutes(),0);
secondhand.eulerAngles.y=Vector3(0,fu.GetSeconds(),0);
}
var zeroHourDegrees: float;
private var hours: float;
private var minutes: float;
private var seconds: float;
function SetTime(degrees: float)
{
//calcs angles
hours=Mathf.Repeat(degrees-zeroHourDegrees,360);
minutes=Mathf.Repeat(hours*24,360);
seconds=Mathf.Repeat(minutes*60,360);
}
function GetHours() float
{
return hours;
}
function GetMinutes() float
{
return minutes;
}
function GetSeconds() float
{
return seconds;
}
may require some tweakage with the first script, but i just used that as an example, with a stationary clock, set up perfectly, but you get the idea,
That’s more than useful, thanks for the code!