[UNSOLVED] Turning Turrets with CFrames, Welds, or Motor6D's Causes Ship to Flip Over?

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?

Is the root priority of the primary part of the ship higher than the turret?

Supposedly, yes. The ship has an invisible primary part (called “bote”) that has a root priority of 10. Everything else in the ship has a root priority of 0.

What are the Density Properties of the Parts involved. If you have differences between them it may cause issues with one taking control over the other.
I have an excavator that uses motor6Ds to control the boom and when I left the seat the angle would inverse. When I got back in the seat it would flip back. A friend told me about the Density issues and after changing them it worked.

1 Like

I have never messed around with Density. I’ve also tried making the turrets massless but that didn’t do anything different.

I have the base and arms on my excavator all set with Density = .1
Having even one of them with a different Density (especially Massless) made a big difference to how they reacted.

In a good way or bad way? I haven’t messed with Density ever before, and this is also my first time dealing with Motor6D’s.

Basically what I said,
Match Densities of the Parts involved for good results.
Make the Densities different and you may get poor results.

Since I didn’t touch part Density at all, I think they’re all already the same density by default.

When I first read the title I originally thought about how welds sometimes don’t update according to a Body mover. As in the body mover like a BodyGyro might think the weld has not changed after you change it. After watching the videos, I think maybe the upvector might be finnicky whenever you create a cframe (consider CFrame.lookAt() instead of CFrame.new()). If you haven’t already, maybe try something like:

local currentCf, toPoint;
newCf = CFrame.lookAt(currentCf.Position, toPoint, currentCf.UpVector)

Are you recommending this instead of the TargetCFrame with targetAngle (direction) that I currently have set up?

If that is a solution then I may be able to somehow make it work, but the problem is that I also need to have constraints on the rotation here (like a hinge) which is measured in degrees. Also, it needs to slowly rotate toward the point rather than instantly aiming there.

The other big clue that’s confusing me here is that it works fine with only one turret, but then when there’s more than one it causes the ship to flip, but only when the guns aim to either side. It gets a little more confusing when you include the fact that one of the ship types flips over even when it only has one gun on it.

Slight update: I changed the root priority of the turret’s rotorPart (the part on the bottom of the turret that connects to the static part on the turret ring) to 1, with the rest of the ship set to 0, and this was the result:

Speaking of this let’s do some further debugging with these visualization methods since the ship should also count as a Motor6D rig, what does the rig look like? Can you visualize it within something like RigEdit lite.

Also are you able to animate in when you add a animation controller?

If so then are the rotations occuring as intended when you try to manually edit it?

Usually you need to follow a similar structure like rootpart → Body → arms like a normal rig which is how I test mine are working as intended with the correct root part.

You cannot really skip the steps such as Body → arms as it causes weird bug issues like the one below :point_down:.

For example this problem:

I don’t exactly know what that would look like (I’ve barely ever messed with Motor6D’s), but it’d probably be very barebones considering I didn’t use any plugins for Motor6D and really all I did was insert a Motor6D through script similarly to inserting a weld. “Bote” is the main part of the model “Boat,” and TurretRing is a child (alongside Bote) of “Boat,” with RingRotor (a basepart) being a child of TurretRing and RotorWeld (the Motor6D) being a child of RingRotor. I have basically been treating the Motor6D like a normal weld except for when I use .Transform, which has the same exact result nonetheless.

To debug further try printing out the root part BasePart:GetRootPart.

I would also suggest moving it to an empty baseplate and see if you could replicate the samething. Also where is the body gyro located?

Personally I’m guessing the C0 is effecting the body gyro part which is causing the rotation, some sort of chain effect.

Also I made an alternative method using CFrame.lookAt with constraints. And the rig thing I mentioned is this, if you select the model with RigEdit lite, it helps debug where the joint positions are which greatly influence the movement and rotation center of the turrets.

Currently, there doesn’t seems to be enough information and hence requires more debugging. Is the body gyro the problem? Any code related to CFrames?

Which part should I call :GetRootPart on?

The body gyro is located in the part “bote” (an invisible part roughly in the middle of the ship and elevated a bit above it), which is a child and primary part of the model “Boat” (the whole ship). The gun (a model) is also a child of Boat. “TurretRing” (a flat cylinder part fixed to the hull of the ship, doesn’t turn) is also a child of Boat, and RingRotor (a small base part fixed to TurretRing, doesn’t turn) is a child of TurretRing, with RotorWeld (the Motor6D) being a child of RingRotor and connected to Rotor (a child of gun, does turn).

Here’s a crude label of the hierarchy (it’s probably not too helpful):

Any part works since it’s one assembly they all should have the same root part.

I would also make this part visible since it’s very important to the orientation, also put a decal to see where this part is facing.

I went ahead and tested these.

Bote is the root part, and also bote is oriented forward, and stays oriented forward when it flips. I somewhat knew this already because otherwise the ship wouldn’t remain moving forward when it’s flipped.

Considering that so far the Motor6D attempt I have here has pretty much been playing out exactly the same as the normal weld attempt, is there a way I can make this work with normal welds and c0-setting, or is there something specific now I need to do to get around this issue?