Low fps issue with raycast vehicle

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

any ideas to fix this?

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

times by 1 / 60 makes it stay on the floor and i tried increasing the stiffness and damping to make it pull up more and it doesnt work

dividing by 1 / 60 makes it fling itself

wdym by linking to the onphysics step, im using runservice.heartbeat

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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

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

figured it out
it was the friction math i was doing was very wrong
i fixed that now

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.