#fps affecting physics

1 messages · Page 1 of 1 (latest)

tacit oyster
#

i am trying to make a game and when i put my fps to 240 it works perfectly, but the lower the fps i set it to, the worse it gets (insanely fast acceleration and weird turning) does anyone know how to help or if theres anyway to fix it, ill put the script in the chat if anyone wants to look

remote grove
#

ts is probably cause you use RunService

#

it runs per frame

tacit oyster
#

yeah i do idk what else to use

south gateBOT
#

studio** You are now Level 3! **studio

remote grove
#

ig dont use runservice?

tacit oyster
#

and replace with what

remote grove
#
task.spawn(function()
    while task.wait() do
        --code
    end
end)

maybe with sum like that

tacit oyster
#

ok i will try

echo iris
tacit oyster
#

local now = os.clock()
local dt = math.clamp(now - last, 0, 1/20)
last = now

i got this

echo iris
tacit oyster
#

oh

echo iris
#

RunService.Stepped:Connect(function(dt) end)

tacit oyster
#

RunService.Heartbeat:Connect(function(dt)

i got this now but it still weird

#

it accelerates like 2x speed

echo iris
tacit oyster
#

do u wanna see my full runservice

echo iris
tacit oyster
#
local fwd = speedForward
local df  = targetFwd - fwd
if math.abs(throttle) < 0.05 then
    fwd = fwd * math.max(0, 1 - (DECEL_COAST * dt) / math.max(1, MAX_SPEED))
else
    local accel = (math.sign(targetFwd) ~= math.sign(fwd) and BRAKE_POWER or ACCEL_FWD) * ctrlMult
    if boostMul > 1 then accel *= BOOST_ACCEL_MUL end
    fwd = fwd + math.clamp(df, -accel * dt, accel * dt)
end
fwd = math.clamp(fwd, -speedCap, speedCap)
#

i forgot how u do that lua thing with the `

hollow wren
tacit oyster
#
-- hi
#

oh ok

hollow wren
#

oh god, I've only just noticed that you both have df and dt... that's why I got confused

tacit oyster
#

bro this code is a mess idk what im doing

hollow wren
#

I would just slowly note down all the math you're doing and just then check what needs to get a time influence. Right now I can see a lot of things getting multiplied by dt in clamps and such, but if you don't ever actually do that in the applying then it's useless

#

Also, a quick note:

fdw = fdw + ...
fdw = fwd * ...
*= and += exist, it will already help with readability

echo iris
#

I would suggest naming things more clearly

tacit oyster
remote grove