Collision detection with framerate independend movement

Started by Tspider4, May 07, 2012, 19:45:03

Previous topic - Next topic

Tspider4

I made a small little concept game with framerate independend moving object (entities). I'm calculating a delta (time between frames) and using it in the updated position of an object (like in tutorial 4 -timing- on the lwjgl wiki). When an entitiy is going fast or if the delta gets bigger (on slower computers or when the game will get bigger) the object will seem to "teleport" while trying to keep the same speed. I understand this will happen, and I don't think its a problem. The problem is in the teleporting itself. When an object "teleports" it will crash into other objects or even 'jump' behind them, which ruins my collision detection.

My collision detecting calculates if the objects (Rectangles) are interfering with eachother. When an object 'teleports' over an object in 1 frame, it will never interfere.

What is the best solution to solve this problem?

Thank you,
Tycho

Simon Felix

There are basically three solutions:
1. Instead of checking for collisions with an object at time t and t+1 you can calculate the object that is the overlapping of the original object at all points in time from t to t+1. For example, if you have a disc you would calculate a cylinder with the top being the disc at time t and the bottom being the disc at time t+1. Then do the collision checks with the cylinder. It's hard to do, but accurate.

2. Use fixed time steps. Instead of using variable time steps you could always work with (an example) 10ms time steps. When the actual time difference between 2 frames is 68ms, you'd execute 6x10ms time steps and add 8ms to the next time difference.

3. Use movement subdivision. When an object wants to move 493 pixels and the bounding box is 60 pixels wide you could move the object 9 times (first 8 times by 60 pixels, last time by 13 pixels) and check for collisions every time.

I usually go with #2 and make sure that the top speed of each object is limited somehow.

Need more explanations?
Download Cultris II, the fastest Tetris clone from http://gewaltig.net/

Tspider4

Thanks a lot for your fast reply.
I think I'll go for the fixed timesteps method (#2) , because the first method looks like it will use a lot of computing power.