I am not able to explain verbally so see the videos above.
Here is the code that moves the things:
local function Step(dt)
for i,v in pairs(Gameplay:GetChildren()) do
if v:FindFirstChild("Speed") then
v.Position += UDim2.new(0,0,0,v.Speed.Value * 60*dt)
if v.AbsolutePosition.Y > Gameplay.AbsoluteSize.Y+10 then
v:Destroy()
end
end
end
end
it looks like v.Position += UDim2.new(0,0,0,v.Speed.Value * 60*dt) is the problem
seems like it was written assuming that all clients are running @ 60fps
it should be changed to: v.Position += UDim2.fromOffset(0, v.Speed.Value * dt)
at 60fps the value of dt is 1/60, which is around 0.016… you’re cancelling it out by doing 60 * dt
at 400fps the value of dt is 1/400, which is around 0.0025… which is being multiplied by 60 and causes the sprites/environment to move at 15% of the intended speed
also as a side note since this function is being called every frame, i suggest using some sort of cache system to replace the GetChildren() & FindFirstChild() functions because they’re slow
I will do that but wont it be even slower? and if dt is 1/400 will it not mean that runservice.RenderStepped. The thing I am using to run the Step function. Shouldn’t it run 400 times a second?
I will. The game is not even near completion and its just some test bugs I found.
No, it won’t be slower
i drew a pretty image demonstrating that an object travelling at 5 units per second will travel 5 units in 1 second regardless of framerate:
The 400fps one compensates its speed by doing it ~666% faster though (400/60), which gives us the same speed (0.15 * 6.667 = ~0.999 = 1)
The * 60 part doesn’t matter since it’s multiplied to both calculations, I think OP * 60 so the speed value is more manageable.
it may help to print out the value of dt and the time elapsed between each step (is the calculation too heavy that it has no choice but to yield?). Setting your FPS cap to a value below 400 like 240 or 120 might help to see if it still work as intended.