I am trying to make something more/less visible the bigger/lower this Angle value is, the Angle value being the angle between the camera and a certain part, but it’s not going right and just doesn’t flat out work properly.
The limit for visibility is 0.5, which is what data[“Effects”][“Shear”] is.
angleValue:GetPropertyChangedSignal("Value"):Connect(function()
task.wait()
if angleValue.Value > baseAngle then
print("is not seen")
player.PlayerGui.FightGUI.Static.ImageTransparency = 1
end
if angle >= data["Angle"]["Min"] and angle <= data["Angle"]["Max"] then
if angleValue.Value > angleFromBefore then -- the new value is greater than the starting value
--bigger
print("bigger")
if player.PlayerGui.FightGUI.Static.ImageTransparency < data["Effects"]["Shear"] then
player.PlayerGui.FightGUI.Static.ImageTransparency -= 0.05
else
player.PlayerGui.FightGUI.Static.ImageTransparency = data["Effects"]["Shear"]
end
elseif angleValue.Value < angleFromBefore then -- the new value is smaller than the starting value
--smaller
print("smaller")
if player.PlayerGui.FightGUI.Static.ImageTransparency > 1 then
player.PlayerGui.FightGUI.Static.ImageTransparency += 0.05
end
end
end
angleFromBefore = angleValue.Value
end)
Well if we know what the minimum and maximum angles are, we could perform a simple inverse lerp to find out what percentage the angle is between the min and max angle, then we can use this as an alpha for interpolating the image transparency between 0.5 and 1
local function inverseLerp(min, max, x)
return (x - min) / (max - min)
end
local function lerp(min, max, alpha)
return min + (max - min) * alpha
end
local minAngle = 0
local maxAngle = 120
local currentAngle = 60
local minTransparency = 0.5
local maxTransparency = 1
local alpha = inverseLerp(minAngle, maxAngle, currentAngle) --> 0.5
local transparency = lerp(minTransparency, maxTransparency, alpha) --> 0.75
However since we’re working with 0.5 and 1 being the lower and upper bounds specifically, we can simplify as so:
local alpha = inverseLerp(minAngle, maxAngle, currentAngle) --> 0.5
local transparency = minTransparency * alpha + 0.5 -- 0.75
However note that will only work with 0.5 and 1 being the lower and upper boundaries. If you want to use arbitrary lower and upper boundaries you would need the full equation.