#fps affecting physics
1 messages · Page 1 of 1 (latest)
yeah i do idk what else to use
** You are now Level 3! **
ig dont use runservice?
and replace with what
task.spawn(function()
while task.wait() do
--code
end
end)
maybe with sum like that
ok i will try
Are you using DT from the RunService function?
local now = os.clock()
local dt = math.clamp(now - last, 0, 1/20)
last = now
i got this
RunService already has a parameter for DT, you don't need to calculate it yourself
oh
RunService.Stepped:Connect(function(dt) end)
RunService.Heartbeat:Connect(function(dt)
i got this now but it still weird
it accelerates like 2x speed
Well how are you using DT?
It's in seconds, mostly less than a second (unless things are really laggy)
do u wanna see my full runservice
Maybe just one instance of you using DT for something like speed rather than all of your code
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 `
```lua
```
oh god, I've only just noticed that you both have df and dt... that's why I got confused
bro this code is a mess idk what im doing
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
I would suggest naming things more clearly
oh yeah ok thanks
ok
yeah its not very clear rn
It's hard to come up with good names in code, but its also easy to get wrong. By looking at some examples, we can get 80% of the way there. Access to code examples, discord, song names and more at https://www.patreon.com/codeaesthetic
0:00 Introduction
0:31 Variables with a single letter
1:08 Never Abbreviate
2:06 Types in your names
2:36 Units...