Tempature scaling on time issues

I have made a tempature/weather system within my game where the tempature scales depending on ClockTime however when clocktime swaps from 23 to 0 it completely ruins the crudely put together calculations

game.Workspace.Weather.Tempature.Value =- math.floor(game.Lighting.ClockTime/1*-1)

And i’m not too sure on how to make something more like this

1 Like

Could you elaborate on how you want the temperature calculated and what you expect the temperature to be at certain times?

Basically the darker it is out the lower the temperature

Okay, so let’s start with your bounds.

Your clock time bounds are 0 - 24. However, 0 and 24 are the same thing, which means 12 must be when the hottest temperature is reached and 0/24 is when the lowest temperature is reached. This will be a really weird relationship.

Your temperature bounds (let’s say for example) will be 50 and 100. We will store these bounds in two variables and figure out some mathematic relationship such that 12 will be the hottest temperature and 0/24 is the lowest.

On a graph, this may look like an absolute value function, or an upside-down V shaped correlation. Here’s a graph of this specific scenario.

You can use two linear equations to map your relationship and set up a function to get your temperature. Here’s a function I made that’ll work with any temperature bounds.

local minTemperature = 50 -- CHANGE IF NEEDED
local maxTemperature = 100 -- CHANGE IF NEEDED

local rise = maxTemperature - minTemperature
local run = 12
local slope = rise/run

local getTemperatureFromTime(clockTime: number): number
    if clockTime <= 12 then
        return (slope) * clockTime + minTemperature
    else
        return (-1 * slope) * (clockTime - 24) + minTemperature
    end
end

I hope you have learned some math and I hope this was helpful :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.