I am working on Scopes and I’ve come across an issue, I don’t know how to scale the Reticle Image based on the FOV, I’ve tried making Formulas that would calculate the Size based on FOV % but it got too messy, So I tried making a easier simpler way to scale the Reticle Image, but I’ve run into a Issue the Image scales as I wanted it to but it kinda does it other way Around the Image gets smaller the more zoomed in you are (less FOV the camera has) and bigger the more zoomed out you are (more FOV the camera has).
if VariableZoom and opticSettings[VariableZoom.Parent.Name] then
local Scope = VariableZoom.Parent
local OpticSettingss = opticSettings[VariableZoom.Parent.Name]
for _,v in pairs(Scope:GetDescendants()) do
if v:FindFirstChild("SizeChanger") then
local SizeChanger = v:FindFirstChild("SizeChanger")
v.Size = UDim2.new(math.clamp(CurCamera.FieldOfView,SizeChanger.MinValue,SizeChanger.MaxValue),0,math.clamp(CurCamera.FieldOfView,SizeChanger.MinValue,SizeChanger.MaxValue),0)
end
end
end
(Don’t mind the black sides I am still working on that)
If you know what the maximum and minimum FOV is and can calculate the current/difference you can use that to tween/interpolate the image.
Let’s say your FOV goes from 70 to 50 when scoping in…
local min_fov = 50
local max_fov = 70
local difference = max_fov - min_fov
-- FOV as a percentage / scalar value between 0 and 1.
local current_fov = (workspace.CurrentCamera.FieldOfView - min_fov) / difference
If my math checks out, this should give you a number ranging between 0 and 1.
That number you can use in a lerp function, for instance, lerping Vector3 like this.
local start_vector = Vector3.new(1, 2, 1)
local target_vector = Vector3.new(20, 15, 70)
local interpolated_vector = start_vector:Lerp(target_vector, current_fov)
This is pseudo code but hope it gets the idea across.
I am not sure how to use Lerp, but Using the Percentage formula you gave me I managed to make this script, that scales the ImageLabel Size just as intended.
local SizeChanger = v:FindFirstChild("SizeChanger")
local min_fov = OpticSettingss.ZoomLevels[1] --(25)
local max_fov = OpticSettingss.ZoomLevels[2] --(10)
local difference = max_fov - min_fov
local current_fov = (workspace.CurrentCamera.FieldOfView - min_fov) / difference
local Sizer = math.max(SizeChanger.MinValue,math.min(current_fov*SizeChanger.MaxValue,SizeChanger.MaxValue))
v.Size = UDim2.new(Sizer,0,Sizer,0)
Thank you very much, I’ve been struggling with this for so long, not sure how I haven’t thought about this xd