Raycast Suspension System Issue

  1. What do I want to achieve?

I am trying to make a suspension system for normal cars using raycasting and body thrusts.

  1. What is the issue?

However, the chassis gets unstable and starts moving up and down really fast.

Video:

  1. 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

1 Like

One way to calculate the force is to use PID with the I and D integration and differentiation components which provide a dampening effect.

Here is the PID module which you can use.

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.

1 Like

Also how often is Update thrusters running? Is it in a runservice heartbeat connection? Or is it while true do wait() end?

It’s in a runservice.stepped event

One way to calculate the force is to use PID with the I and D integration and differentiation components which provide a dampening effect.

I actually came across this, but I just didn’t know what it was. I appreciate your help and I will mark your reply as the solution.