I would like assistance with solving the problem which happens at low fps described below for a raycast suspension system which uses vector forces:
Currently I have tried adding a velocity prediction/substep to the drag force which did not work. I believe I have to either add more substeps or add a substep for the spring forces as well.
local function predictVelocity(currentNetForce, mass, currentYVelocity, timeStep : number)
local acceleration = currentNetForce/mass --F = ma
local addedVelocity = acceleration*timeStep --Integrate acceleration, assuming constant acceleration
return currentYVelocity + addedVelocity
end
--prediction code commented out
--Inside an update loop below:
-- local dragYForce = currentYVelocity*damping
-- local currentNetForce = dragYForce + totalSpringForce - workspace.Gravity*mass -- + is up, - is down
-- local velocityPrediction = predictVelocity(currentNetForce, mass, currentYVelocity, dt/2)
-- local averageVelocity = (velocityPrediction + currentYVelocity) * 0.5
-- local newDragYForce = averageVelocity*damping
local newDragYForce = currentYVelocity*damping
-- print(roundToDecimal(currentYVelocity, 2), roundToDecimal(velocityPrediction, 2))
self._vectorSpringDragForce.Force = Vector3.new(0,-newDragYForce,0)
The latest full code is in the GitHub in the HipHeight component module.
Thank you if you are able to providing any help.
I should head to sleep now, probably will work on the suggested ideas and solve the issue once I get time.