Im trying to make this tank turret smoothly rotate, but when I move over a certain angle, it freezes and snaps into place.
Video:
Code:
local RotateM6D = Turret["Left/Right"].PivotBase.PivotWeld
local TiltM6D = Turret["Up/Down"].PivotBase.PivotWeld
local RotateDir = Vector3.new(screenRayDir.X,screenRayDir.Y,screenRayDir.Z)
local RLworldRotationCFrame = CFrame.new(RotateM6D.Part0.Position, RotateDir)
local rotateGoalCF = M6DController.cframeObjectRotation(RotateM6D, RLworldRotationCFrame)
local relativeCF = RotateM6D.Part0.CFrame:ToObjectSpace(CFrame.lookAt(RotateM6D.Part0.Position, screenRayDir, RotateM6D.Part0.CFrame.UpVector))
local rx, ry, rz = relativeCF:ToOrientation()
local clampedRY = math.clamp(math.deg(ry), Settings.XLimit[1], Settings.XLimit[2])
local rotateC0 = CFrame.new(rotateGoalCF.Position) * CFrame.Angles(0,math.rad(clampedRY),0)
local oldX, oldY, oldZ = RotateM6D.C0:ToOrientation() -- old orientation
local newX, newY, newZ = rotateC0:ToOrientation() -- new orientation
local displacement = newY - oldY -- distance
local tweenTime = displacement * (Settings.TurretRotationSpeedX / 100)
local rotateTweenInfo = TweenInfo.new(tweenTime, Enum.EasingStyle.Linear)
local rotateTween = TweenServ:Create(RotateM6D, rotateTweenInfo, {C0 = rotateC0})
rotateTween:Play()