So I am trying to make a turret that will rotate facing towards a target position at all times, and it is working to some degree. However, I am having trouble getting the horizontal rotation to work. I am using HingeConstraint
allow for it to spin. For some reason, it won’t spin past a certain angle. in both direction.
Here is the video:
Here is my code:
local model = script.Parent
local hingeHorizontal = model.HorizontalRotatingPart.HingeConstraint
local hingeVertical = model.VerticalRotatingPart.HingeConstraint
local target = workspace.Enemies.Enemy.HumanoidRootPart
local sentry = model.VerticalRotatingPart
while wait() do
local newCFrame = CFrame.new(sentry.Position, target.Position)
hingeHorizontal.TargetAngle = math.deg(newCFrame.LookVector.Z)
hingeVertical.TargetAngle = -math.deg(newCFrame.LookVector.Y)
end
Note: hingeVertical works completely fine. hingeHorizontal is the problem.
Also, when the angle is supposed to be 90 or -90, it get stuck around 57 or -57 degrees.
At about 50 or -50 degrees, its rate of change starts to get smaller and smaller until it reaches ± 57 degrees.
I don’t know what I am doing wrong. Can someone please help me?