I’m currently working on making all the turrets on my ships turn via setting the c0 of their welds. What I’ve found is that they works just fine when the ships have only one gun, but the ships freak out and flip over when they try to turn more than one gun. More specifically, they freak out and flip over when the guns point to the sides, but not when they point forward/backward between around -30 degrees and 30 degrees or so. The ship’s body gyro will slowly flip the ship back over as long as the guns are kept pointed forward/backward. (Note: the ship and all of its parts are NOT anchored.)
I have tried multiple methods, from using welds and setting the CFrame of their c0, to using Motor6D’s and setting their c0’s, to using Motor6D’s and setting their DesiredAngle. I’ve tried fiddling with RootPriority values and stuff a little too. Every single one of these methods mysteriously yields the exact same result: the ship flips over when the guns turn to the side.
I should note that the turrets worked just fine back when I used hinges to rotate them (the reason I’m replacing the hinge system is because it increased physics lag sixfold).
Here’s part of my code, specifically the part that turns the turret:
--This code loops through each individual turret on heartbeat. There's more code above it too which calculates for direction.
local rotorWeld = turretRing.RotorWeld --RotorWeld is a Motor6D (or a Weld, depending on which attempt I'm taking, but they both work similarly) that connects the Turret to the Turret Ring (the part on the ship that the turret connects to, and this part does not turn), with Part0 being the Turret Ring and Part1 being the Turret.
local targetCFrame = CFrame.Angles(0, math.rad(direction * rotationSpeed), 0) --Direction is -1 or 1 or 0, depending on which way the turret needs to rotate, and rotationSpeed is roughly 1.
rotorWeld.C0 *= targetCFrame --Adds the rotation to the rotor's current rotation. I've also used rotorWeld.Transform *= targetCFrame here and got the exact same result.
I also have some videos I can show:
Here the ship has only one turret, and it works just fine.
Here the ship has two turrets, and it flips over. (The turrets’ rotation becomes inverted because the ship is upside-down now and that messes with the calculations.)
I’ve also noticed that one of the ship types SPECIFICALLY still has the problem even when it has only one turret. I’ve also noticed that the problem can potentially cause the ships to spin if they’re angled vertically:
What could be occurring with the c0-setting between all these guns that causes the whole ship to flip over? I’ve been trying to figure this out for the past three days now. Can someone help me figure this out?