So I’m trying to be able to use a hinge to rotate the turret around the Y axis relative to the vehicle and another hinge to move the gun up and down. I was using a BodyGyro and setting the CFrame to cframe.new(position1, position2) where position1 is the base of the turret and position2 is where it needs to aim. This works, but it feels rather unpolished inconsistent with the speed at which the turret moves, so I’m trying to switch over to using the hinges. I’m not particuluarly good at trig, and figuring out how to get the turret to aim in the correct place with using the TargetAngle of hinges is proving to be quite difficult for me.
What I have right now only partly works. It works when the tank is on completely flat ground, and when it’s facing a very precise direction. Here’s what I have so far and a video demonstrating what it does.
local x1, y1, z1 = CFrame.new(turret.Base.Position, endPosition):ToObjectSpace(base.CFrame):ToOrientation()
local x2, y2, z2 = CFrame.new(gun.Base.Position, endPosition):ToObjectSpace(base.CFrame):ToOrientation()
turretHinge.TargetAngle = -math.deg(y1)
gunHinge.TargetAngle = -math.deg(x2)
Any help with this problem will be greatly appreciated!