Using my game loop to give my game movement which is independant from the framerate, has been working fine for me but, I've started to consider my games running on machines which cannot keep up with my expected frame limit of 60fps, I've tried manually setting it to a lower cap and noticed that my collision detection starts to go off and objects on screen overlap because of this.

How can I make collision detection occur on movements which are too great and overshoot boundary checks?

Below is my loop for running my game

  while (g_Window.isOpen()){

    sf::Time dt = clock.restart();
    timeSinceLastUpdate += dt;
    while(timeSinceLastUpdate > TIME_PER_FRAME){

         timeSinceLastUpdate -= TIME_PER_FRAME;
  • \$\begingroup\$ No. But the fewer collision checks, the less accurate it will be. \$\endgroup\$
    – Evorlor
    Commented May 14, 2015 at 11:35

1 Answer 1


I'm not sure if you're speaking of inability to keep up with FPS or UPS (Updates Per Seconds), but if machine has lower frames per second than expected you shouldn't change rate at which you're logic is being updated (UPS). Content of window is drawn depending on machine's capabilities but logic (and physics) run at constant and independent rate. In this situation you can precisely predict where sprite (or whatever) will be since logic which moves sprite and physics which detects collision run at the same rate (UPS).

Example: Logic runs at 60 Hz - UPS, but your machine can only process game loop 30 times per second, so your FPS is 30. One loop iteration takes longer than 60 Hz, so update(...) might be run few times, but that's ok, because you move sprite by distance * UPS and your collision detection system (assuming it's called after sprite update) detects that sprite will collide so it moves sprite back to safe area. Same result would be if you check if sprite will collide before moving it: if(!border.getGlobalBounds().contains(sprite.getPosition().x + sprite.getSize().x + distanceX * ups, sprite.getPosition().y + sprite.getSize().y + distanceY * ups)) sprite.move(distanceX * ups, distanceY * ups);


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .