# clear collisions

• 01-07-2004
Benzakhar
clear collisions
I can check if 2 objects are colliding. But when to objects travel 10 pixels per frame and they are 2 pixels square then there is a change I won't detect it. How should I check if there is a collision or not and set the 2 objects in the corect position of where they will collide?

• 01-08-2004
ninebit
The way to do it is to use collision in time.

Say you have two objects with pos and vel as follows:
p1 = (x, y) + t(a, b)
p2 = (z, w) + t(c, d)

where x, y (and z, w) is last frame pos, and t(a, b) is velocity times frametime. This is ordinary framerate regulated movement.

now you can take these two points and write the relationship (distans) between then as an equation. Remember pythagoras??

Now here is the cool part:
what you have now is a function describing the distanse, and this distans depends on time!

there are several ways to go from here:
1. divide the frametime (t) into smaller parts and test each of these time slices for collision. less precision though.

2. if you derive the original equation you get an equation where you have a minimal point. solve for t, and you will have the time when this min point occurs. great! now put this time in the original equation to get the minimum distans between the objects under the frametime.

from here on either way goes the same: normal collision detection, either box, circle, pixelprecise. but now you have the exact time the collision will occur.

Well this was kinda simplified, cause solving the equations takes one page when using pen and paper... there might be other ways to do this, this one being almost only mathematical...

best of luck to you, hope any of this helped!
• 01-09-2004
Nor
Quote:

Originally posted by ninebit
1. divide the frametime (t) into smaller parts and test each of these time slices for collision. less precision though.

Code:

//    float t = 1/FramesPerSecond;

float t = 1/(FramesPerSecond * 2);

one problem with line 2 ^^
you need a loop

FramesPerSecond = 65
average_time_between_frames = t =
0.0153846153846153846153846153846154
this is usually enough to detect a colision

circle dection is quicker so its best to run it first. long as the
radis's are set to the most distance vertce from its axis it will
never produce a false negitave.

pixelprecise - can u explan some more
• 01-10-2004
ninebit
I agree that circle (sphere) should be used íf possible, since it easy and fast.

pixel precise, would be for a 2d game to test each pixel of the two collidion objects (bitmaps?) to see if there is a collision. although its quite nice to have this type of precision on the collision detection, I find that it is not worth it in most games, since the playser will never know the precission is that good anyway. obviously you should use circle or rect collision detection before you do pixel collision, if no collision in the first test, there will never be a collision in the pixel collision.

This applies also to 3d games, but there you use polygonal precise collision once the bounding volumes have collided. poly collision would test every polygon on the two object to find collision, roughly speaking. there several ways to do this i'm sure.
• 01-10-2004
Salem
Well you do it in two steps

Use a circle method which is quick, but you make the circle radius equal to the speeds of the objects.

If they fall inside the larger circle, then you can do a more detailed calculation on the subset of objects which are "close" together.