hello !
So i’m finishing a thing for an Undertale project i’m doing for fun, and I realised that when I tween a position of an image label, and with random orientation, the tweening act weird. Here is a video of what I mean :
Any idea how I could fix it? Script :
local debounce = script.Parent.Parent.debounce
local RunService = game:GetService("RunService")
local debounce = false
local label = script.Parent
local frame = script.Parent.Parent.MainFrame.Heart
local TweenService = game:GetService("TweenService")
local Object = script.Parent
local tweenInfo = TweenInfo.new(
1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.In
)
local Tween = TweenService:Create(Object, tweenInfo, {Rotation = 270})
Tween:Play()
Tween.Completed:Wait()
local labelPos = label.AbsolutePosition
local framePos = frame.AbsolutePosition
local diff = labelPos - framePos
local deg = math.deg(math.atan2(diff.X, diff.Y))
label.Rotation = -deg - 89.5
script.Parent.Event:Fire(script.Parent.Parent.MainFrame.Heart.Position)
function collidesWith(gui1, gui2)
local gui1_topLeft = gui1.AbsolutePosition
local gui1_bottomRight = gui1_topLeft + gui1.AbsoluteSize
local gui2_topLeft = gui2.AbsolutePosition
local gui2_bottomRight = gui2_topLeft + gui2.AbsoluteSize
return ((gui1_topLeft.x < gui2_bottomRight.x and gui1_bottomRight.x > gui2_topLeft.x) and (gui1_topLeft.y < gui2_bottomRight.y and gui1_bottomRight.y > gui2_topLeft.y))
end
while wait() do
if collidesWith(script.Parent, script.Parent.Parent.MainFrame.Heart) then
if debounce == true then return end
debounce = true
game.Players.LocalPlayer.Character.Humanoid.Health -= math.random(10,12)
wait(0.5)
script.Parent:Destroy()
end
end
-- Script 2 so it can run independently (Ik I could have use couroutine)
script.Parent.Event.Event:Connect(function(target)
wait(0.5)
script.Parent:TweenPosition(target , Enum.EasingDirection.In, Enum.EasingStyle.Sine, 0.5)
wait(0.5)
script.Parent:Destroy()
end)
Thanks a lot to Embat who helped me with the rotation finding