Archived

This topic is now archived and is closed to further replies.

Game clock, frames per second, missed collisions...

This topic is 5744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some general questions regarding updating scenes, clock handling, frames per second, and avoiding missed collisions. Phew! Assume a simple scenario of objects being fired with some initial angle and velocity. My code is calculating object position using the time elapsed since firing the object, and some simple math formulas. The problem is, if the frames-per-second drops(for whatever reason, let''s just assume this happens), object movement starts looking very choppy. Worse, the choppiness may get so bad that objects may "pass" through each other without colliding. Instead of flying they are basically "skipping" through space. I have some theories on how to approach this(such as maintaining my own clock), but can some of you veterans clue me in on the tried-and-true techniques? To summarize... how do you handle drops in framerate gracefully, and how do you avoid lost collisions? Thanks! Todd

Share this post


Link to post
Share on other sites
use a fixed time step game loop, see gamedev.net and flipcode.com (tip or code of the day archive) for more info. this ensures yoru physics is irrelevent of the framerate and it could plummet to only 3frames per second, and you would get the same accuracy as 1000 frames per second. though the actual accuracy depends on how often you update, you probablly wil choose about 30-60 times a second for the physics/logic of the game. also consider using line/rect intersection tests instead of pt/rect tests. since you can then trace the path of the projectile better, and ensure no matter how fast the projectile moves you will get a somewhat )since projectiles take a curved path and you are checking using lastpos to the curpos which is a line) accurate collision detection (at the cost of speed of code, and some other complexities to ensure the accuracy).

Share this post


Link to post
Share on other sites