Hello, I am making a top down shooter game using only gui and am having issues lerping the rotation of turrets without them flipping when they reach one side.
Here is the code for it, I have tried some stuff but I could not get anything to work so I ended up undoing it
local MainUI = script.Parent.Parent.Parent
local Player = MainUI.Player
local Turret = script.Parent.Turret
local Cannon = Turret.Top
local sine = 0
function Lerp(a, b, t)
return a + (b - a) * t
end
game["Run Service"].RenderStepped:Connect(function()
sine+=1
Turret.Gear.Rotation=sine*2 -- just for looks
local difference = (Player.AbsolutePosition - Turret.AbsolutePosition)
local rot = -math.deg(math.atan2(difference.X, difference.Y))
Turret.Rotation = Lerp(Turret.Rotation,rot,.05) -- rotate with lerp to make it smooth
print(rot)
print(Turret.Rotation)
end)
If anyone knows of a solution for this I would be very grateful!