Trouble With Custom Friction and FPS

Hello everyone, I’m working on a ball racing game where friction isnt reliant on Roblox physics and rather it’s own calculation. My current issue is when the FPS lowers, not enough friction is applied and when FPS is higher too much friction is applied. I want players to all have have the same opportunities and power despite framerate

Visualization:
Low FPS

Intended FPS

Here is my friction code:

game:GetService("RunService").RenderStepped(function(dt)
  local ThisMarble = --Just a part
  local CurrentPush = 100
  local PushModification = 0
  local Friction = 0.035

  local Delta = 60 / (1/dt)
  print(Delta)
  ThisMarble.Velocity = ThisMarble.Velocity:Lerp((Input * (CurrentPush + PushModification)* 1 ^ Delta), Friction) * (Vector3.new(1,0,1) + (ThisMarble.Velocity * Vector3.new(0,1,0))) 
end)

I’ve tried tons of different methods but all either send me to the floating point error zone or just have no effect at all. Any help is appreciated!

Edit: Added missing friction variable to code my bad :B

Using Heartbeat instead of RenderStepped in the first line should probably help the issue.

1 Like

This does negate the issue however control feels off, as if its running way slower than it should.

(Actually the delta doesnt even do anything
1^x is always 1)

In order to properly scale the thingy by time I would probably just do something like

local frictionPerSecond = 0.1 --idk something you want that seems right

rs.RenderStepped:Connect(function(dt) 
    --unrelated stuff

    marble.Velocity = ThisMarble.Velocity:Lerp(blahblahblah, frictionPerSecond*dt)*blahblahblah
end)
1 Like