Skip to main content
Updated to respond to comment
Source Link
ThorinII
  • 469
  • 4
  • 8

You have a variable called deltaSeconds, which I presume is declared something like: float deltaSeconds in your Player update code.

You can work out a threshold that deltaSeconds can cross, at which you can consider your game to be lagging. For example, if your game runs at 30fps normally, deltaSeconds should be roughly ~0.033f. If the fps degrades to 20fps, it will be 0.05f.

So you need to work out a good value for deltaSeconds to be greater than to be considered lag.

As to what you can do to fix lag - you could clamp how far an object can move in one frame, or you could clamp the deltaSeconds to your threshold.

I/others can elaborate more if needed.

EDIT (I can't comment yet): Even if you want unlimited fps, I'd imagine you still have a minimum desired rate. You don't want your game running at less than a certain fps, but you'd like it to run anywhere faster than that. That should be your lag threshold.

You have a variable called deltaSeconds, which I presume is declared something like: float deltaSeconds in your Player update code.

You can work out a threshold that deltaSeconds can cross, at which you can consider your game to be lagging. For example, if your game runs at 30fps normally, deltaSeconds should be roughly ~0.033f. If the fps degrades to 20fps, it will be 0.05f.

So you need to work out a good value for deltaSeconds to be greater than to be considered lag.

As to what you can do to fix lag - you could clamp how far an object can move in one frame, or you could clamp the deltaSeconds to your threshold.

I/others can elaborate more if needed.

You have a variable called deltaSeconds, which I presume is declared something like: float deltaSeconds in your Player update code.

You can work out a threshold that deltaSeconds can cross, at which you can consider your game to be lagging. For example, if your game runs at 30fps normally, deltaSeconds should be roughly ~0.033f. If the fps degrades to 20fps, it will be 0.05f.

So you need to work out a good value for deltaSeconds to be greater than to be considered lag.

As to what you can do to fix lag - you could clamp how far an object can move in one frame, or you could clamp the deltaSeconds to your threshold.

I/others can elaborate more if needed.

EDIT (I can't comment yet): Even if you want unlimited fps, I'd imagine you still have a minimum desired rate. You don't want your game running at less than a certain fps, but you'd like it to run anywhere faster than that. That should be your lag threshold.

Source Link
ThorinII
  • 469
  • 4
  • 8

You have a variable called deltaSeconds, which I presume is declared something like: float deltaSeconds in your Player update code.

You can work out a threshold that deltaSeconds can cross, at which you can consider your game to be lagging. For example, if your game runs at 30fps normally, deltaSeconds should be roughly ~0.033f. If the fps degrades to 20fps, it will be 0.05f.

So you need to work out a good value for deltaSeconds to be greater than to be considered lag.

As to what you can do to fix lag - you could clamp how far an object can move in one frame, or you could clamp the deltaSeconds to your threshold.

I/others can elaborate more if needed.