I am trying to make a suspension system for normal cars using raycasting and body thrusts.
What is the issue?
However, the chassis gets unstable and starts moving up and down really fast.
Video:
What solutions have I tried so far?
I’ve looked at other dev forum articles about car suspensions and even hover cars. At this point, all I know is that I need to dampen the forces somehow. I did so much research on this topic that I don’t know what to do anymore. I really need someone to point me in the right direction. If I need to apply an equation to my code, please explain it so that I understand what the equation does (That is because I don’t have much experience with physics).
Here is my current code:
--I used the jeep code as a base
local function UpdateThruster(thruster, p)
local position = raycast(thruster, p)
p.Position = position
local MaxForce = 2000
local CurrentHeight = (position - thruster.Position).magnitude
local Quotient = CurrentHeight / stats.Height.Value
local CompressionRatio = 1 - Quotient
--Apply upwards force based on compression ratio
local Force = CompressionRatio * MaxForce
thruster.UI.Label.Text = math.round(CurrentHeight)
thruster.BodyThrust.Force = Vector3.new(0, Force, 0)
end
Note: I’m not trying to make anything too realistic
Also how often is Update thrusters running? Is it in a runservice heartbeat connection? Or is it while true do wait() end? Either way we can use PID for that.
I’m not too sure of the jeep method but it should work since it works for the jeep, I guess I can take a look into it later.