hello!
my chassis utilizes raycast suspension, and everything works fine however it behaves differently and inconsistently on different frame rates; below 30 is practically unusable and upwards of 60 it drives too fast.
here is an example:
ive checked out other forum posts that face the same issue, however they were of little help
here is my code
-- in a while true loop,
-- delta = game["Run Service"].Heartbeat:Wait()
for wheel_name, original_position in pairs(chassis_configurations.wheel_positions) do
local chassis_cframe = chassis_primary.CFrame
local ray_origin = chassis_cframe:ToWorldSpace(CFrame.new(original_position))
local ray_direction = -chassis_cframe.UpVector * (chassis_configurations.suspension_max_length + chassis_configurations.wheel_radius)
local ray_params = RaycastParams.new()
ray_params.FilterDescendantsInstances = {chassis}
local raycast = workspace:Raycast(ray_origin.Position, ray_direction, ray_params)
if raycast then
local raycast_distance = (ray_origin.Position - raycast.Position).Magnitude
local spring_length = math.clamp(raycast_distance - chassis_configurations.wheel_radius, 0, chassis_configurations.suspension_max_length)
local stiffness_force = chassis_configurations.stiffness * (chassis_configurations.suspension_max_length - spring_length)
local damper_force = chassis_configurations.damper * ((spring_length_memory[wheel_name] - spring_length) / delta)
local suspension_force_vector3 = chassis_cframe.UpVector * (stiffness_force + damper_force)
local rotations_only_wheel_direction_cframe = CFrame.lookAt(Vector3.zero, chassis_cframe.LookVector, chassis_cframe.UpVector)
if string.sub(wheel_name, 1, 1) == 'f' then
rotations_only_wheel_direction_cframe = rotations_only_wheel_direction_cframe * CFrame.Angles(
0,
-math.rad(chassis_smooth_steer * chassis_configurations.steer_angle),
0
)
end
local local_velocity = rotations_only_wheel_direction_cframe:ToObjectSpace(CFrame.new(chassis_primary:GetVelocityAtPosition(raycast.Position)))
local x_force = rotations_only_wheel_direction_cframe.RightVector * -local_velocity.X * chassis_configurations.wheel_friction
local z_force = rotations_only_wheel_direction_cframe.LookVector * seat.ThrottleFloat * chassis_configurations.torque * (
math.sign(-local_velocity.Z) == seat.Throttle and (
1 - math.min(1, math.abs(local_velocity.z)/chassis_configurations.max_speed - chassis_module.chassis_cons)
) or 1
)
spring_length_memory[wheel_name] = spring_length
chassis_primary:ApplyImpulseAtPosition(suspension_force_vector3 + x_force + z_force, ray_origin.Position)
else
spring_length_memory[wheel_name] = chassis_configurations.suspension_max_length
end
end
id have to assume this is an issue associated with how i used delta but i am clueless nonetheless