Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Holding a Position while manipulating it...?

Asked by 9 years ago

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))
0
What does that mean? How can something be at two places at once? Specify what you mean better. BlueTaslem 18071 — 9y
0
I want the ImageLabel to be shaking in the middle of the screen. It's hard to do that when you can't set the position of where the "math.sin(tick() * 100)" is. peoplemove12 148 — 9y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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)
Ad

Answer this question