So I am trying to set up a Turret automatically using Servos, however when I create the Attachments I need to rotate them in order for the Servo to have the correct orientation. But this causes the Turret Base to also rotate, which is undesired.
This only happens when I make the Attachments through script. Manually creating them and rotating them works, however this is not good enough because there will be hundreds of different turrets, so it needs to be automated.
The result of doing it through script
How it should look (ignore the barrel, it’s yet to be implemented)
Here is how I’m generating the attachments and the servo:
local Direction = Identifier:GetAttribute("Forward")
local H1,BAtt1
if Direction then
H1 = Instance.new("Attachment")
H1.CFrame = H1.CFrame*CFrame.Angles(math.rad(0),math.rad(-90),math.rad(90))
BAtt1 = Instance.new("Attachment")
BAtt1.CFrame = H1.CFrame*CFrame.Angles(math.rad(0),math.rad(-90),math.rad(90))
H1.Parent = Identifier
BAtt1.Parent = Model.Turrets[Identifier.Name].Base
else
--TODO
end
local BaseServo = Instance.new("HingeConstraint")
BaseServo.Attachment0 = H1
BaseServo.Attachment1 = BAtt1
BaseServo.ActuatorType = Enum.ActuatorType.Servo
BaseServo.LowerAngle = -145
BaseServo.UpperAngle = 145
BaseServo.LimitsEnabled = true
BaseServo.AngularResponsiveness = 45
BaseServo.AngularSpeed = 2
BaseServo.ServoMaxTorque = math.huge
BaseServo.SoftlockServoUponReachingTarget = false
BaseServo.TargetAngle = 0
BaseServo.Parent = Identifier