Hi I was wondering how Vector2 values, if possible, can be converted to Udim2 values , as in do the X and y from the vector 2 represent the offset or scale component, respectively
1 Like
Yes.
local V2 = Vector2.new(5,2)
--converting to scale
local scale = UDim2.new(V2.X,0,V2.Y,0)
--converting to offset
local offset = UDim2.new(0,V2.X,0,V2.Y)
--or you can have them represent the Width/height
local ud = UDim.new(V2.X,V2.Y)
local UD_Width = UDim2.new(UDim.new(),ud)
--or
local UD_Height = UDim2.new(ud,UDim.new())
--or using 2 vector2
local v1 = Vector2.new(5,2)
local v2 = Vector2.new(2,5)
local ud1 = UDim.new(v1.X,v1.Y)
local ud2 = UDim.new(v2.X,v2.Y)
local UD1 = UDim2.new(ud1,ud2)
local UD2 = UDim2.new(ud2,ud1)
2 Likes
I tried using it like you did for scale and it does not work
It wouldn’t work for scale considering that a Vector2 is expressed in pixels across the screen. It only works as far as offset goes, if you intend to use a raw Vector2 value for UDim2 inputs.
I can’t quite remember how to convert a Vector2 to scale - I believe it involves dividing one of the coordinates by the matching coordinate of the AbsoluteSize of the Gui. Scale is expressed in a percentage so this should make sense.
6 Likes
Here a link to a blog post about it if anyone needs it in the future
6 Likes