Help with scripted suspension falling to the floor

  1. What do you want to achieve? I am trying to create my very own custom scripted suspension system

  2. What is the issue? The car falls to the ground because of gravity, adding any force or removing gravity will break the suspension system. multiplying the force will also break it

robloxapp-20230106-1516142.wmv (950.7 KB)

The spring is functioning properly… it’s just not pushing up against gravity
The script works on small parts though, 1x1x1 is the biggest a part can be before it falls to the ground though

Here is the code:

local d = 6 -- Suspension Distance

local a = 1.8 --Stiffness, higher means higher height at suspension
local b = 0.6 --Rigidity higher means the suspensions will get less effected 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}, {dx=0,d2x=0}, {dx=0,d2x=0}, {dx=0,d2x=0}} -- FL, FR, RL, RR

function Spring(suspension_distance, STN)
	local x = d - suspension_distance --X is how much the suspension is contracted

	local f = a*x + b*(x-ST[STN].dx) + b/2*(x-ST[STN].d2x) --Use the equation

	ST[STN].d2x = ST[STN].dx --Store the past values
	ST[STN].dx = x
	return f

local params =
params.FilterDescendantsInstances = {script.Parent}

while wait() do
	for i,v in pairs(script.Parent.Forces:GetChildren()) do
		local pos = v.Attachment0.WorldPosition
		local cast = workspace:Raycast(, pos.Y + 0.1, pos.Z),, -100, 0), params)
		if not cast then continue end
		local dist = (pos - cast.Position).Magnitude
		local f = Spring(dist, i)
		v.Force =, f, 0)

The script is an adapted version of this

Quick look at it, you probably should set the force to zero if the ray doesn’t hit anything. Currently it will maintain it’s current force if it doesn’t.

Otherwise you should use attributes and play around with the values, it is entirely possible to have a weak spring that doesn’t have enough stiffness.

This is not what is causing the vehicle to fall to the floor

as I said the spring is working just fine on smaller parts. the mass of the vehicle is the problem
increasing the stiffness, adding to the force, or multiplying it causes the vehicle to move very rapidly or too slowly, no matter how much I adjust them

Edit: The script works on small parts though, 1x1x1 is the biggest a part can be before it falls to the ground though

You may want to check this script out, it’s a raycast suspension script made by ROBLOX.

It seems you linked to the documentation on vehicleseats? I do not see anything about a raycast suspension system