# Mathematics for Car Suspension System

Hi, I was wondering what mathematics I would need to know to get started with a car suspension system (Like the ones from jailbreak). I already saw a few posts about this but they all had calculus and deriving equations which I don’t understand fully. The scripts on the threads automated springs without actually needing spring constraints which is something I would like to do. Is there any way I can made a suspension system without high level mathematics or any links that could help explain it? Thanks.

3 Likes

Could you include the articles you’ve tried in your post? To get a better understanding of where you sit and what we should be avoiding in addressing a helpful solution to your problem?
The Jailbreak cars use the same suspension method as the freemodel jeep in the toolbox. It’s been discussed many times and uses a force inversely proportional to the distance of the wheel well to the ground.
There’s unique caveats too, like keeping the thrusters inside the hitbox / collision boundary of the full vehicle to avoid them clipping through terrain (as they are often not colliders) and applying the force to drive the vehicle into the ground.
To give a rough answer I would say it’s not too mathematically intensive, you just have to decide how your going to apply that force given the variable distance, which I think can be done with just an inverse square function.

Here are a few articles I looked at:

And I also took a look at the free model jeep as one of the threads mentioned it could help, but I couldn’t make much sense of any of it. Also, in the first post OseDay had commented with a formula which used hookes law in a second order problem (which I don’t really understand that well). Also I don’t really understand what you meant when you said use a inverse square function at the end of your reply and how I could apply it to my solution. This is my first time really dealing with cars so you’ll have to bear with me if I don’t understand some of the terms your using.

It’s Oseday, not OseDay.

Here’s a script for you to implement it:

``````local Engine = ... --main part of the car

local WheelDistanceFromGround = 1.75
local WheelRayDistance = 3.5
local Rigidity = 0.35

local CarMass = ...
local CarCenterofMass = ...  --in object space of the engine

Engine.TorqueAttachment.Position = CarCenterofMass

local Wheels = {}
do --Create wheels
local WheelCount = 0
for _,Wheel in pairs(Car.Wheels:GetChildren()) do
if Wheel:IsA"Part" then
WheelCount+=1
end
end
for _,Wheel in pairs(Car.Wheels:GetChildren()) do
if Wheel:IsA"Part" then
Wheels[#Wheels + 1] = {
CFrame = Engine.CFrame:inverse() * Wheel.CFrame,
Stiffness = 1/WheelCount,
Rigidity = Rigidity,
dx = 0,
d2x = 0,
}
end
end
end

game:GetService("RunService").Stepped:Connect(function(tik,dt)
local EngineCF = Engine.CFrame
local EnginePos = EngineCF.Position
local CarCOM = EngineCF * CarCenterofMass

local ForceTotal = Vector3.new()
local TorqueTotal = Vector3.new()

--do suspension per wheel
for i,Wheel in pairs(Wheels) do
local WheelCF = EngineCF * Wheel.CFrame
local WheelPos = WheelCF.Position
local raycastResult = workspace:Raycast(WheelPos, WheelCF.UpVector * -WheelRayDistance, rayParams)

if raycastResult then
local x = (raycastResult.Position - WheelPos).magnitude
x = (WheelRayDistance - x)/(WheelRayDistance - WheelDistanceFromGround)

local F = x*Wheel.Stiffness + Wheel.Rigidity*(x-Wheel.dx) + Wheel.Rigidity/2*(x-Wheel.d2x)
F *= workspace.Gravity * CarMass
F *= WheelCF.UpVector

Wheel.d2x = Wheel.dx --store the past values
Wheel.dx = x

local NormalF = F:Dot(raycastResult.Normal)*raycastResult.Normal - F

ForceTotal += F + NormalF
TorqueTotal += F:Cross(CarCOM - WheelPos) + NormalF:Cross(CarCOM - raycastResult.Position)
end
end

Engine.Force.Force = ForceTotal --in world space
Engine.Torque.Torque = TorqueTotal --in world space
end)
``````
4 Likes

Not trying to be rude or anything but if you had read my initial post, I asked if it was possible to make a suspension system without any high level mathematics like calculus. What I’m trying to do is understand what formulas I’m using in my scripts, not just copy them down. (also sorry for mistyping your name earlier)

Then use constraints. I use constraints and they work out very well! Remember that constraints exist for a reason

I’m working on realistically simulating cars at the moment

Oh, sorry for the late response (haven’t been able to access my PC for other reasons). Right now I’m trying to make it without anything that already does the suspension for me (so that I can use scripts). Do the constraints your talking about need scripting for them to work?

Not the constraints themselves, but for the vehicle to move, naturally yes.

A suspension is a damped spring, you cannot create a suspension without damped springs therefore you need to know the physics and math of a damped spring to create a suspension which includes the “high level mathematics”. Obviously those are the mathematics you need to know which were said and explained in the article.

http://hyperphysics.phy-astr.gsu.edu/hbase/oscda.html

It’s literally just: `F = ma = -kx -cv`

2 Likes

Wait… I am confused

Why is stiffness`1/wheelcount`

And what is `WheelRayDistance` here

1 Like

Stiffness is probably 1/wheelCount because each wheel needs less and less stiffness the more wheels you have

So with 2 wheels the stiffness would be 1/2
With 4, 1/4
With 8, 1/8

This way the “total” stiffness will always add up to 1, because 8 eighths is 1, 4 fourths is 1, 2 halves is 1, etc

WheelRayDistance is the distance that the car will be able to raycast to see the ground, its basically like the maxed out, completely stretched out length of the suspension where it cant extend any more

2 Likes

First of all thanks for the info you provided

Second of all

What is `wheeldistancefromground` then?

The “balance point” of the suspension, how high it will be at its resting position and how high it wants to be

2 Likes

Super easy!

This doesn’t show vehicle suspension physics.