Renderstepped delta time spikes

Hi, I have this issue where I’m using renderstepped with delta time for stuff like recoil and springs

If the framerate is low enough, the delta time will spike really high, making the camera recoil and springs bounce around really weird
image
Lagger script clamps my fps to 10 and shows delta time

What can I do to fix this, am I doing anything wrong?

1 Like

Try making your own delta time using by using the UNIX epoch time. Either use os.time(), tick() or DateTime.now() (all but DateTime are deprecated but you can still use it to test). If that is the actual amount of time that has passed since the actual frame you will need to find another solution.

2 Likes

Hi, tried using tick() but it’s the same issue

I managed to find a post related to the issue I’m having here:

1 Like

when your fps are lower the time between each frame is longer (which is delta)
so you should try to fix the lag spikes instead

the game itself will be unplayable at 10 fps

2 Likes

The game itself doesn’t have any major lag spike issues - I’m here looking for a fix for this issue because I heard complaints from people who play on low end machines

1 Like

If that is the actual amount of time that has passed since the last frame then you need to find an alternative to using DeltaTime.

If you’re trying to optimize for low end devices I would at minimum optimize for 30fps because anything lower than will be difficult for players no matter what.

Also within the post you provided the error is with RunService.Stepped. Try experimenting with other events such as RenderStepped or Heartbeat.

1 Like

Both deltatime and tick yield the same result. As GE_0E said, this issue - afaik - is intended behavior.
I’m rather looking for a way to fix it.

Also the post mentions renderstepped

1 Like

the reason why delta time is used is to make the changes the same on any fps
for example,

120fps will move a part by 1 stud 120 times per second
60 fps will move a part by 2 stud 60 times per second
30 fps will move a part by 4 stud 30 times per second

all of these examples are moving the same studs
if 30 fps moved the part 1 or 2 studs per frame then the change of the part position will not be constant across all fps

the only thing to stop the weird movement is to not use delta time but then the amount of change will not be constant across all fps

2 Likes

Thanks for the explanation on delta time purpose

Little unrelated I guess, but for context:
My viewmodel script pushes the camera up every frame to simulate recoil based on a cframe value, which is lerped to zero each frame using delta time

What would be the proper way to do this, if not delta time?

2 Likes

your way is already correct and not using delta for this will cause the recoil for low fps players to be very low and will cause the recoil for high fps players to be very high delta is used to keep the recoil the same across any fps

2 Likes

Thanks, the issue might be somewhere else, then
I’ll look into it for now

1 Like

This won’t fix the lag issue but you could multiply the cframe offset by deltatime * 60 so it adjusts based on the fps

2 Likes

Thanks for the tips guys

I tried removing the deltatime from the previously mentioned Lerps and it seems to have made it correct across all FPS?

I think this might be something weird in my code, rather than the delta time itself

1 Like