Lighting ClockTime math help

I’m trying to make a function based off the lightings ClockTime, that outputs between 0 and 1

Return 1 when ClockTime is at its highest (14)
Return 0 when ClockTime is at its lowest (0)

This will be used to have fog colors based on time of day, ambient color etc.

My problem is that the lighting ranges between 0-23.99, and I’d like the return value to be 1 when the time is 14 rather than 12.

Hopefully you can somewhat understand what I’m trying to accomplish.

1 Like
local maxDistance = 12 -- The furthest distance the clock will ever be away.
local desiredTime = 14 

local getNumber = function(clockTime)
    local distance = math.abs(desiredTime - clockTime) 
    local percentAway = distance/maxDistance -- Will give you 1 for 100% away and 0 for directly ontop of.
    local percent = math.abs(percentAway - 1) -- Reverts it around, giving you 1 for 0 and 0 for 1.
    return percent
end

Hope this has the effect you are looking for.

Note - There probably are more efficient ways to do this math.

2 Likes

This is currently the most accurate to what I need, thank you.

1 Like