I wanted to make an offset updater for my dialogue UI, since I cannot use scale as it goes mayham.
So, how do I exactly update the UI from the previous pos/size to the new one when the area it is currently on has been scaled? (let’s say the viewport size on the camera)
I tried using this formula:
newOffset = oldOffset * (newViewportSize / oldViewportSize)
local txt = script.Parent
local txtOldSize = UDim2.new(0, txt.Size.X.Offset, 0, txt.Size.Y.Offset)
local AreaOldSize = Vector2.new(txt.Parent.AbsoluteSize.X, txt.Parent.AbsoluteSize.Y)
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.X then
txt.Size = UDim2.new(0, txtOldSize.X.Offset*(txt.Parent.AbsoluteSize.X/AreaOldSize.X), 0, txtOldSize.Y.Offset*(txt.Parent.AbsoluteSize.Y/AreaOldSize.Y))
txtOldSize = UDim2.new(0, txt.Size.X.Offset, 0, txt.Size.Y.Offset)
AreaOldSize = Vector2.new(txt.Parent.AbsoluteSize.X, txt.Parent.AbsoluteSize.Y)
end
end)
but it ended up changing the UI size to just 0,0,0,0
(Or is it just I suck)