I’m making a scripted chassis, but it doesn’t work as intended, here is my code:
local d = 2
local a = 1000 --Stiffness, higher means higher height at suspension
local b = 0.6 --Rigidity higher means the suspensions will get less affected by slight changes and will balance out, unlike Roblox's suspensions. This is the part that dampens the suspension.
local ST = {dx=0,d2x=0} --For storing the derivatives per suspension
local sus_height = 4
local mass = 0;
for _, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("BasePart") then
mass = mass + v:GetMass()
end
end
while true do
--For every suspension, in this case, 4 of them
for _, Wheel in pairs(wheels) do
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {Wheel}
local ray = workspace:Raycast(Wheel.Position, Vector3.new(0, -10, 0), params)
if ray then
local distanceToGround = (Wheel.Position - ray.Position).Magnitude
local suspension_distance = (sus_height - distanceToGround)
local x = d - suspension_distance --X is how much the suspension is contracted
local f = a*x + b*(x-ST.dx) - b/2*(x-2*ST.dx+ST.d2x) --Use the equation
ST.d2x = ST.dx --Store the past values
ST.dx = x
platform.Thrust.Force = Vector3.new(0,f,0) --Apply the forces
Wheel.Thrust.Force = Vector3.new(0,-f,0)
else
Wheel.Thrust.Force = Vector3.new()
end
game:GetService("RunService").Stepped:Wait()
end
end
It doesn’t push the wheels down nor push the car up.
I have connected the wheels using cylindrical constraints, and I am using VectorForces instead of BodyThrusts.
Here’s an image of how the chassis looks when I run the game;
Help is appreciated, thank you for reading