How to tween UI away from a UI

So, how could I tween a UI away from a UI?

I tried to make this but it doesn’t go the opposite direction of the UI.

Code:

local direction = (absolutePos - newClicksLabel.AbsolutePosition).Unit

local offset = 30

local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local tween = TweenService:Create(newClicksLabel, tweenInfo, {Position = newClicksLabel.Position + UDim2.new(0, direction.X * -offset, 0, direction.Y * -offset)})
tween:Play()
1 Like

I’m not sure what you’re trying to do here, do you mind posting some screenshots of expected behavior and actual behavior?

Instead of going in the opposite direction of the UI, you can use a random angle and tween it away from the UI in that direction:

local randomAngle = math.rad(math.random(0, 360))
local direction = Vector2.new(math.cos(randomAngle), math.sin(randomAngle))

local offset = 30

local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local tween = TweenService:Create(newClicksLabel, tweenInfo, {Position = newClicksLabel.Position + UDim2.fromOffset(direction.X * offset, direction.Y * offset)})
tween:Play()

I’m not sure if this is what you were looking for, but I may be able to help with more details.

1 Like

But I set the position on this line already:

newClicksLabel.Position = mousePos + UDim2.new(0, math.random(-80, 80), 0, math.random(-80, 80))

so thats why I need it to tween away from the mousePos.

I’m sorry, I’m really not sure what you’re trying to say.

Can you show me a specific example of what you’re trying to do?

The video shows the Clicks textlabel tweening away from the mouse:

I have something you can try.

Replace

newClicksLabel.Position = mousePos + UDim2.new(0, math.random(-80, 80), 0, math.random(-80, 80))

with

local randomAngle = math.rad(math.random(0, 360))
local direction = Vector2.new(math.cos(randomAngle), math.sin(randomAngle))

local initalOffset = 30
local finalOffset = 80

newClicksLabel.Position = newClicksLabel.Position + UDim2.fromOffset(direction.X * initalOffset, direction.Y * initalOffset)

local tweenInfo = TweenInfo.new(0.4, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0)
local tween = TweenService:Create(newClicksLabel, tweenInfo, {Position = newClicksLabel.Position + UDim2.fromOffset(direction.X * finalOffset, direction.Y * finalOffset)})
tween:Play()

Let me know if that works.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.