For example, I get a number with a value slowly going from 0 to X. Would it be possible for the final value to be 0.75 to 1?
Another example that might make more sense:
If the current value is 0.5, the expected value should be 0.875, if the current value is 0, the expected value should be 1, and if the current value is 320, the expected value should be 1.
I understand if this makes completely 0 sense, but I appreciate any help!
Not quite sure if that’s the solution, I’ll check it out in a sec, but I’ll go in to depth with what I’m trying to do.
Basically, I am making a horror game and I’m currently creating the Heartbeat effect system so that when you go closer to the entity, the more the effects will show. And the last effect will be just a red frame tweening its transparency (sort of like Apeirophobia). I want the BackgroundTransparency of the frame to be between 0.75 and 1, based off of the Heartbeat SFX’s PlaybackLoudness. I am just trying to figure out to get the value.
Ah yes, you’ll need the lerp function then for the 0.75 to 1
local frame = script.Parent
local sound = workspace.Sound
local rs = game['Run Service']
local beatDownAggressiveness = 0.1
local beatUpAggressiveness = 0.9
local function lerp(a, b, t)
return a + (b-a)*t
end
function inverseLerp(a, b, x)
return math.clamp((x-a)/(b-a), 0, 1)
end
local lastT = 0
RunService.Heartbeat:Connect(function(deltaTime)
local t = inverseLerp(0, 1000, sound.PlaybackLoudness)
if t >= lastT then
t = lerp(lastT, t, beatUpAggressiveness))
else
t = lerp(lastT, t, beatDownAggressiveness)
end
frame.BackgroundTransparency = lerp(0.75,1,t)
lastT = t
end)