Hi, I'm making a billboard gui. When a player gets close, the billboard gui becomes twice as small. But how can I calculate how big it should be when it is twice as small?
for i, child in pairs(billboardgui:GetChildren()) do local halfsize = child.Size <== child:TweenSize(halfsize) end
As per the API reference and what DeceptiveCaster said, using a UDim2
involves four properties: xScale, xOffset, yScale, & yOffset
ex. a GuiObject with the size of UDim2.new(1, 0, 1, 0)
will take up 100% of the space (both x and y axes) of the parent object.
A potential way to get half the size of a UDim2 is to subtract the the value of the scale properties by 0.5. (Using a math operation between the size of the GuiObject and a new UDim2 with 50% scale on whichever axes you want to halve.)
https://developer.roblox.com/en-us/api-reference/datatype/UDim2#math-operations
This might help:
local billboardgui = script.Parent.BillboardGui wait(5) --// function for dividing Scale and offset of a UDim2 vector space function HalfUDim2(sze) local UD2W = sze.Width local UD2H = sze.Height --// make sure any element are Not 0 if they are, then just set Half Scale/Offset to 0 --// if we didn't check this we would be dividing by 0 which is impossible! --// format Scale not eq = 0 then set Scale/2 or set it to 0 local XS = UD2W.Scale ~=0 and UD2W.Scale/2 or UD2W.Scale local XP = UD2W.Offset ~= 0 and UD2W.Offset/2 or UD2W.Offset local YS = UD2H.Scale ~=0 and UD2H.Scale/2 or UD2H.Scale local YP = UD2H.Offset ~= 0 and UD2H.Offset/2 or UD2H.Offset return UDim2.new(XS,XP,YS,YP) end for i, child in pairs(billboardgui:GetChildren()) do local halfsize = HalfUDim2(child.Size) local halfpos = HalfUDim2(child.Position) child:TweenSizeAndPosition(halfsize, halfpos) -- changed this as we're changing the size of each element, what you had before only resized the elements but not change the position so i've included it into this equation with the above function! end
let me know if you need more info!
Hope this helps!
for i, child in pairs(billboardgui:GetChildren()) do local halfsize = child.Size/2 child:TweenSize(halfsize) end