How would I convert real-world time to in-game time?

I’m working on adding an in-game clock, and the basic logic is pretty simple:

seconds += DeltaTime;
if (seconds >= 60){
	seconds = 0;
	minute += 1;
	if (minute > 60){
		minute = 0;
		hour += 1;
		if (hour > 23){
			hour = 0;
		}
	}
}

This gives me the real-world passage of time, but where I’m conceptually stuck is how to convert it to in-game units. I have some int DayInMinutes which indicates how long, in real-world minutes, 24 in-game hours should take, but what’s the most efficient way to actually multiply the clock’s behavior based on this?

1 Answer

1

Perhaps take the current time in seconds and multiply it by a factor? So if you x2 then your in game clock would take 12 hours to go through a 24 hour cycle (using the same conversion of seconds to time as you would do for real world).

x4 = 6 hours
x8 = 3 hours

I’d also only update your in game visual clock every 10-20 frames (if you are displaying sub-second values)

HTH