Hello there!
I am using sleitnick’s PID to ensure a vehicle stays on the road using my chassis, but it appears to go a bit too far and then too far the other way, never actually coming closer to the intended positioning, as seen in this clip: sleitnick's pid going left and right extremely
Module: https://github.com/Sleitnick/RbxUtil/blob/main/modules/pid/init.lua
My script:
local steeringPID = PID.new(-100, 100, 200, 50, 0)
steeringPID:Debug("PIDDebug", workspace)
local function keepInMiddle(delta, target, vehicle)
vehicle.KIM.Value = target
local desiredsteer = target.Orientation.Y
local currentsteer = vehicle.PrimaryPart.Orientation.Y
local steer = steeringPID:Calculate(desiredsteer, currentsteer)
steer = steer * math.min(delta * module.Car.Model.Seats.Driver.TurnSpeed.Value * 10, 10)
mod.Car.attachments.FL.Orientation = Vector3.new(0, vars.steer, -90) -- these two just apple the orientation to the front wheels
mod.Car.attachments.FR.Orientation = Vector3.new(0, vars.steer, -90)
end
game:GetService("RunService").Stepped:Connect(function(dt)
keepInMiddle(dt, workspace.Road:WaitForChild("guide"), workspace:WaitForChild("FordTransitTrend"))
end)
Does anyone know how I can patch/fix this?
Thanks for reading!