Motorcycle with PID turns into spinning helicopter blade when I turn too sharply

My motorcycle goes crazy when I turn too sharply, I tried adjusting all the PID module parameters but none of them fixed my issue.

local PID = require(ReplicatedStorage.PID)
local BalancePID = PID.new(-3000, 3000, 100, 80, 0)

local function update(deltaTime: number)
	local tilt = root.Orientation.Z
	local force = BalancePID:Calculate(deltaTime, 0, tilt)
	root.BalanceForce.Force = Vector3.zAxis * force
end

RunService.Heartbeat:Connect(update)

You can also use a AlignOrientation

With these settings

take note of the Mode, AlignType and PrimaryAxis

and then you can use the CFrame property to tilt the bike

1 Like

Can you clarify how I am suppose to tilt the motorcycle with the CFrame property of AlignOrientation?

You don’t have to, the AlignOrientation instance already helps you does that. Also, there is no CFrame property in it.

There is, take a look at the documentation.

I followed @5uphi’s instructions and it is not working.

Can I see your current code? if that helps.

There is no code for AlignOrientation though. If you are talking about the PID, it’s on my original post.

I don’t think AlignOrientation instance would work in such instance. So, I believe we should be sticking to PID, though I never heard what is this thing.

I see, I am not a geek in using that, so I can’t really help you much…

here is a demo that uses AlignOrientation

Motorcycle.rbxl (42.7 KB)

and this is the script I used to tilt the motorcycle

local runService = game:GetService("RunService")
local model = script.Parent

local tiltAmount = 1

runService.Heartbeat:Connect(function(deltaTime)
	local rightVector = model.Part.CFrame.LookVector:Cross(Vector3.yAxis) * (model.VehicleSeat.SteerFloat * tiltAmount)
	model.AlignOrientation.PrimaryAxis = (Vector3.yAxis + rightVector).Unit
end)

if you want to control more then one axis then you would need to set PrimaryAxisOnly to false and then use CFrame to rotate

but in the demo I have PrimaryAxisOnly set to true so i use AlignOrientation.PrimaryAxis to set the angle

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.