How could I make it so the position of this ImageLabel is always "UDim2.new(0.5, -210, 0.5, -210)" -- Middle of the screen
but at the same time, this function is working:
SSLogo.Position = UDim2.new(0.5, math.sin(tick() * 100), 0.5, math.sin(tick() * 100))
Of course you can set the position simply.
Think about (.5, -210, .5, -210)
as a position.
I will use this definition for brevity:
local wave = math.sin(tick() * 100)
Think of the wave
contributing to a displacement -- not a position on the screen, but an amount to move. But a displacement on its own isn't a position. position + displacement --> position
. So we have to separate the position
and displacement
in the code you provided. Then we'll just change the position
to the new one.
-- The original: UDim2.new(0.5, wave, 0.5, wave) -- Equivalent: UDim2.new(0.5, 0 + wave, 0.5, 0 + wave) -- Equivalent: UDim2.new(0.5, 0, 0.5, 0) + UDim2.new(0, wave, 0, wave) -- position + displacement
Thus we just use instead
UDim2.new(.5, -210, .5, -210) + UDim2.new(0, wave, 0, wave) -- or, if you prefer, UDim2.new(.5, -210 + wave, .5, -210 + wave)