const float MIN_DT = 1./60;
game loop {
float dt = time_between_frames();
float clamped_dt = (dt>MIN_DT)?MIN_DT:dt;
update_world(clamped_dt);
render();
}
Thanks for the answers :) clamping the time-step seems like a good idea :) However I don't like the idea of fixed timesteps, if you have a pc that can handle 80fps instead of 60, why not?
Another quick question: when setting sf::RenderWindow::setFrameLimit(60) the movement isn't constant at all. The ball quickly increases and decreases speed in a certain pattern. I guess that when a limit is set and you call sf::RenderWindow::display() before a time of 1/60 has passed after the previous one it waits.
i think you have to setFrameLimit() before you create() the window.Nope, you can set it whenever you want and it's setFramerateLimit(). ;)
How do you make your ball move ? Do you use a sf::Clock to get the exact amount of time elapsed between frames ?Yes, I did read the tutorials unlike many others :)
The fixed time-step only applies to the physics update. You can still run your main loop and render at 1000fps if u like, but the idea is to stabilise the physics on the machine and across other machines. In my current game, for example, I run everything at 60fps except the physics, which is run at 30fps, and I interpolate frames in the renderer, so it looks smooth but leaves me with enough CPU for all the other tasks.Oh that way, I'll keep that in mind if I ever write a bigger game with physics then, thanks :)
i think you have to setFrameLimit() before you create() the window.No I did not :) it's the first line after sf::RenderWindow::create().
maybe as you said, your initial frame time is too large. You may change your collision code to check if the ball pass the bat instead of colliding.And what has this to do with ball speeding and slowing with sf::RenderWindow::setFramerateLimit()?
For example if previously the ball is on top of the bat, and in the next frame the ball is below the bat a possible collision might have occurred. (Another check is necessary to determine if this is a false positive)
Next you can then resolve the a 2D line intersection equation to check the exact location of collision with the bat. The first line is from the current ball position to the next ball position. The second line would be your bat.
If an intersection occur, then it means a collision has occur.
Using this method, the collision is not so dependent on the time step being small.
Not sure if this helps