Glitchy scripted suspension?

Hi, I’ve been attempting to code scripted suspension for my hovercar, however it seems that whenever it falls it seems to glitch a little in terms of stuttering and I can’t seem to understand why it’s happening.

Equation used: x * a - x rate * b
Where x is the compression, a is the spring constant, and b is the damping coefficient

Section of code responsible for calculating forces:

do
    local x = spring_rest_length - length -- compression of the spring
    local last_x = (state.last_compressions[v] or x) -- the last compression of the spring

    state.last_compressions[v] = x

    local spring_f = x * spring_stiffness
    local spring_d = ((x - last_x) / dt) * damping_k

    if spring_d > 0 then
        spring_d = 0
    end

    local f = Vector3.new(0,spring_f + spring_d, 0)

   v.vector_force.Force = f
end

Thanks for any help!

probably roblox physics is interfering you can try to put it inside runservice presimulation or postsimulation.
presimulation is like stepped
postsimulation is like hearthbeat
but those are now deprecated

The new roblox runservice events haven’t been enabled yet if I’m not wrong. Anyways, I don’t think it’s likely to be a Roblox physics problem.

i am pretty sure it is just the car hitting the ground that does it

If you look closely, the jittering action occurs before hitting the ground. It may also jitter when at the spring free length height from the ground although it is not visible in the video.

I think it could be a vector force problem you could try updating the position by yourself and not via a vector force

Updating position imperatively would mean that I would not get access to features provided by default with Roblox physics like inertia and collisions so that is unfortunately not an option.

NOTE: It seems that the car can get very unstable and fling out of the world when dropped from a high height too.

can you gave me the stiffness, damping and length values so I can test it?

Free length: 3 studs
Damping coefficient: Given by the formula c = 2 * (k * m) ^ 0.5 where k is the spring constant and m is the mass.
The spring constant, or stiffness as you refer to it as is given by weight of the vehicle / quantity of springs