Some background information first
suspension difficulties
When testing my car chassis system with a frame unlocker I’ve been noticing that the car accelerates a lot faster, and this makes sense because I’m calculating the force in the heartbeat function which is tied to the game’s framerate, in turn affecting the car physics as if the game is running higher than 60 fps the forces are being applied too quickly (sorry my drawing skills are terrible)
and if the game is running slower than 60 fps the forces are being applied too slowly.
For handling suspension, I’ve been trying to use a delta time ratio method (dt*60) to apply the appropriate forces using math to the car so the dampened harmonic oscillators do not become unstable and in turn flip and bounce the car around. This method has had varying degrees of success and could be improved upon.
Acceleration problems
Another issue is that the car accelerates too fast when there is a higher framerate because the driving force is also calculated through heartbeat.
as seen here (360 fps gameplay):
we can compare this to the 60 fps gameplay and see a noticeable difference
as seen here (60 fps gameplay):
My actual question
What can I do to resolve this issue, I’ve been at it for days but I still cannot think of a way to make the forces I am calculating frame independent.
Here I’ve put the force calculation code
Wheel.SpringLength = math.clamp(Wheel.Raycast.Distance - Config.WheelRadius, 0, Config.MaxSuspensionLength)
Wheel.StiffnessForce = Config.SpringStiffness * (Config.MaxSuspensionLength - Wheel.SpringLength)
Wheel.DamperForce = Config.DamperStiffness * ((Wheel.SuspensionLength - Wheel.SpringLength)/FixedDeltaTime)
Wheel.SuspensionForce = Vector3.yAxis * (Wheel.StiffnessForce + Wheel.DamperForce)
Wheel.Velocity = Wheel.RotationOnlyWheelDirectionCFrame:ToObjectSpace(CFrame.new(self.Chassis:GetVelocityAtPosition(Wheel.Raycast.Position)))
Wheel.XForce = Wheel.RotationOnlyWheelDirectionCFrame.RightVector * -Wheel.Velocity.X * Config.WheelFriction
Wheel.ZForce = Wheel.RotationOnlyWheelDirectionCFrame.LookVector * Wheel.Velocity.Z * Config.WheelFriction/10
Wheel.DriveForce = Wheel.RotationOnlyWheelDirectionCFrame.LookVector * self.VerticalMove * Config.Torque
Wheel.GravityForce = workspace.Gravity * Wheel.Raycast.Normal
Wheel.WheelForce = Wheel.SuspensionForce + Wheel.DriveForce/DeltaTime + Wheel.GravityForce/FixedDeltaTime + Wheel.ZForce/DeltaTime + Wheel.XForce/DeltaTime
You may’ve noticed a variable named FixedDeltaTime this is the aforementioned delta time ratio it is calculated like so:
local FixedDeltaTime = 60*DeltaTime
Anyways, I am multiplying all forces by DeltaTime which is clearly a problem but multiplying them by the FixedDeltaTime (which is actually a terrible name now that I think about it, because its not fixed at all but really just a ratio) is basically just multiplying by an insanely high number because any DeltaTime value is a lot smaller than 1.
Regardless, any help on the topic would be greatly appreciated, thank you!