Servo Is offset (Hinge constraints)

I have a turret on the back of my rover, and I want it to rotate to the mouse’s position. It’s working… slightly. The turret seems to be offset by 45 degrees. Example Below:
(I know how to spell would, there’s just no space)

Script that moves the turret:

local delta = CurrentPlayer:GetAttribute("MousePosition") - script.Parent.Turret.Gun.Main.CFrame.Position
script.Parent.TurretHinge.TargetAngle = math.deg(math.atan2(-delta.Z, delta.X))

Edit: I have edited the code to this:

local delta = CurrentPlayer:GetAttribute("MousePosition") - script.Parent.Turret.Gun.Main.CFrame.Position
script.Parent.TurretHinge.TargetAngle = math.deg(math.atan2(-delta.Z, delta.X)) - 45

It fixed it a little bit but not fully

image

Ok this is literally the second time today that I solved my own problem because I was capable of doing it but stupid enough to post it. For anyone wondering how I solved it, it wasn’t offset by 45, it was offset by 90. So my code now is:

local delta = CurrentPlayer:GetAttribute("MousePosition") - script.Parent.Turret.Gun.Main.CFrame.Position
script.Parent.TurretHinge.TargetAngle = math.deg(math.atan2(-delta.Z, delta.X)) - 90

If you need to do this it's probably because of the starting angle of your hinge constraint

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