BodyGyro problem

Hi!

I’m having an issue with BodyGyro where I have a ship and trying to make a wobble effect when it goes left to right. I managed to get an effect going, but when I turn the ship 180 degrees the wobble effect switches sides (video below). It’s also a little buggy because if the ship is moving forward for a couple seconds it starts to steer off course to the left or right and I cant figure out why.

The ships rudder is green in the video and the bodyGyro(D = 100, Torque = (0, 0, inf), P = 500) is on the rudder. The ship also moves forward with a VectorForce on the forward vector.

snippet of the turning right code

local function goRight(actionName, inputState) 
	if inputState == Enum.UserInputState.Begin then
           --setting the bodyGyro 
		character.Rudder.BodyGyro.CFrame = character.Rudder.BodyGyro.CFrame * CFrame.Angles(character.Rudder.BodyGyro.CFrame.X, character.Rudder.BodyGyro.CFrame.Y, math.rad(10))
		-- If the player holds down the button, turn right
		connectionRight = runService.Heartbeat:Connect(function(dt)
			character.Rudder.CFrame = character.Rudder.CFrame * CFrame.Angles(0, math.rad(1) * dt * -60, 0)
		end)
       --when the player stops holding the D key, it stops turning the ship to the right and balances the ship back into the middle.
	elseif inputState == Enum.UserInputState.End then
		character.Rudder.BodyGyro.CFrame = character.Rudder.BodyGyro.CFrame * CFrame.Angles(character.Rudder.BodyGyro.CFrame.X, character.Rudder.BodyGyro.CFrame.Y, -math.rad(10))
		connectionRight:Disconnect()

	end
end

You’re going to run into some confusion while you’re mixing setting CFrame directly and using BodyMovers.

I would recommend choosing one or the other and sticking to it.

You currently have something like this situation:

  1. The BodyGyro is set to rotate the rudder on the Z-axis by 10 degrees
  2. Every frame, the BodyGyro approaches that goal.
  3. Every frame, the CFrame tries to rotate on the local Z-axis (but that would actually put the ship further into the water or the sky BTW)
  4. The next frame, the BodyGyro attempts to bring the rudder back to its original position
  5. The CFrame and BodyGyro continue to fight for dominance over the ship’s steering, with unpredictable results.

Yeah makes sense. Instead of using the CFrame to turn the ship what could I use?

How many BodyGyro’s do you have in the model?

Just 1 on the rudder

Hmmm. There are a lot of ways, but off the top of my head you could do something like this:

  1. Make the “rudder”/“engine” part handle physics, movement and steering with a BodyForce/BodyPosition and a BodyGyro (apply MaxTorque on the Y-axis only though!)
  2. Make the actual visual part of the ship handle tilting with a separate BodyGyro (X/Z-axis only)

Then you need to attach the visual part to the engine part somehow without hindering the affected part’s BodyGyro’s ability to tilt.

You could probably use some constraints for that (maybe an AlignPosition and AlignOrientation+PrimaryAxisOnly). Or you could use RunService.Stepped and set the CFrame if you’re careful about how you go about it.

1 Like

Another way would be to go full physics simulation and just put a bunch of BodyThrusts everywhere (maybe + some constraints)

1 Like