Pacejka car friction model makes the car jitter and i don't know why

hello, so recently I have developed a car chassis using a raycast suspension and the Pacejka friction model. But there is an issue, the car vibrates constantly at high/low speeds here is how I implemented it

function pacejka(slipAngleDegrees)
	local x = slipAngleDegrees
	local B = 1
	local C = 1
	local D = 1.3
	local E = -1

	return D * math.sin(C * math.atan(B * x - E * (B * x - math.atan(B * x))))

local multiplier = 60 / (1 / dt)

local tirePushingGroundValue=springLenghts[i]/restSpringLenght-- the problem isn't here
local tireVelocity = carCenterMassPart:GetVelocityAtPosition(rayResult.Position)
local cf=carCenterMassPart.CFrame
if i==1 or i==2 then
local rv= cf.RightVector
local lv= cf.LookVector
local lateralVelocity = tireVelocity:Dot(rv)
local longitudinalVelocity = tireVelocity:Dot(lv)
local slipAngleDeg = math.deg(math.atan2(lateralVelocity,longitudinalVelocity)) 
local pacejkaValue = pacejka(slipAngleDeg)
local tireLoad = carCenterMassPart.Mass*tirePushingGroundValue
local lateralForce = (tireLoad * pacejkaValue) / 4
carCenterMassPart:ApplyImpulseAtPosition(multiplier*(-1*carCenterMassPart.CFrame.RightVector * (lateralForce)),rayResult.Position)-- the issue is probably here but don't know any other way to apply the force in an responsive way

code is taken from here
the result:

thank you for your time :happy3:

fixed by implementing a lateral friction clamp (can be found here also it has some amazing vehicle handling concepts that you can learn from too)

local lowerValue = (tireLoad*lateralVelocity*lateralVelocity)*dt
local upperValue = ((tireLoad*lateralVelocity*lateralVelocity)*dt)*-1

if lowerValue > upperValue then
	lowerValue, upperValue = upperValue, lowerValue
lateralForce = math.clamp(lateralForce, lowerValue, upperValue)

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