Quick problem, I’m working on a turret using only mouse inputs and frames (no constraints, welds, or motors). Whenever the mouse goes close enough to the turret’s origin it seems like it doesn’t know what it should do with itself, causing it to spin out. Not too sure what’s causing this or how to fix it.
local hit = Mouse.Hit
local goalCFrame = CFrame.lookAt(turret.Body:GetPivot().Position, hit.Position)
local x,y,z = goalCFrame:ToOrientation()
local clampedx = math.rad(math.clamp(math.deg(x),-30,30))
local clampedy = math.rad(math.clamp(math.deg(y),-30,30))
local clampedGoalCFrame = CFrame.fromOrientation(clampedx,clampedy,z)+turret.Body:GetPivot().Position--maintain the turret position so add it
Good first troubleshooting step is to add prints for the different inputs into your calculation so you can see which may be problematic when the cursor is too close to the turret. A hacky fix might be to require the distance from the mouse hit to the turret be greater than a certain number before attempting to pivot