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