so i been making a raycast based car for a while now but if the fps of the player gets below 60 fps (thats a stable 60 fps, like around 50 fps this starts to happen) the car will start bouncing around
im using vector forces to keep it up
i tried to take the suspension math and times by delta time but that just make the issue worse, or it never kept it above the ground
video:
calculations:
function module:calculateMotor(dt, hit, throttle)
local forward = self.attach.CFrame.LookVector
local velocity = getVelocityAtPoint(self.attach.Parent, self.attach.WorldPosition)
velocity = self.attach.Parent.CFrame:VectorToObjectSpace(velocity)
velocity = Vector3.new(velocity.x, 0, velocity.z)
local currentSpeed = velocity.Z
local torque = self.torque
local maxSpeed = self.maxSpeed
if throttle < 0 then
maxSpeed /= 2
torque /= 2
end
local force = throttle * torque * (1 - math.min(1, math.abs(currentSpeed) / maxSpeed))
return forward * force
end
function module:calculateSlip(dt, hit)
local right = self.attach.CFrame.RightVector
local forward = self.attach.CFrame.LookVector
local velocity = getVelocityAtPoint(self.attach.Parent, self.attach.WorldPosition)
velocity = self.attach.Parent.CFrame:VectorToObjectSpace(velocity)
velocity = Vector3.new(velocity.x, 0, velocity.z)
local props = nil
if hit.CustomPhysicalProperties then
props = hit.CustomPhysicalProperties
else
props = PhysicalProperties.new(hit.Material)
end
local mass = ((self.attach.Parent.AssemblyMass + self.mass) * workspace.Gravity)
local trueFriction = props.Friction * self.gripFactor
local force = (-velocity * trueFriction * mass) * dt
return right * force, -forward * force
end
function module:calculateSpring(offset)
local velocity = getVelocityAtPoint(self.attach.Parent, self.attach.WorldPosition)
local up = self.attach.CFrame.UpVector
local length = offset - self.wheelRadius
local spring = self.stiffness * (self.restLength - length)
local damper = self.damping * velocity.Y
local force = (spring - damper) * up
return force
end
Well, I have to worry you a bit. Because instead of using delta time to upgrade the velocity of the attachment, you should be using a const value of 1/60.
(or try linking your script with the onphysics step event (means you can use deltatime that is the most precise to what you want it to be))
It looks like you are experiencing a problem with “bouncing” when the frame rate drops below a certain threshold. This can be caused by a number of different factors, such as changes in the physics engine’s time step or changes in the smoothness of the player’s input. Here are a few potential solutions you might try:
Make sure that your code is using delta time ( dt ) correctly. This can help to ensure that the physics engine’s time step is consistent, even if the frame rate varies.
Consider using a fixed time step for your physics calculations. This can help to reduce the amount of variation in the physics engine’s time step, which can lead to more stable behavior.
Make sure that your forces are applied correctly. Make sure that your forces are being applied at the correct points in the physics engine’s update loop, and make sure that they are being applied correctly based on the mass and velocity of the object.
Check for other sources of instability in your code. This could include issues with your raycasting, problems with your vehicle’s mass or inertia, or problems with your suspension or tire models.
everything is working fine its something with the suspension once the fps drops
i try doing * dt, doesnt work i try doing / dt, doesnt work i try using 1 / 60 for dt and that doesnt work
the tire models are fake they dont collide with anything or have any physics. the raycasting is fine, my math is fine i tested all of this its only the suspension when the fps drops