Collision detection for fast moving objects?
What you're going to do is essentially create a vector(line) between where the object is, and where it's going to end up. Then you check to see if that line intersects any other objects. If it does, you probably have a collision, though the tests may get more in depth depending on how accurate you want your collision code to be.
Jonathan
What i was thinking i needed to do was break down the speed and do collision checks every few pixels. Example
ball is moving at 16 pixels
i would take the ball break the 16pixels moved down to 4 collision checks 1 for each 4 pixels moved.(this would help reduce the amount of checks needed and still be pretty acurate.)
My problem was implementing something like this.
I think a better way would be to calculate the vector your object is making by moving (the line from origin to destination) and check if your other object collide with this vector. Or, for large object, calculate 2 vector (from the 2 point farthest apart perpendicular to your midle vector).
ex.:
Let say you have a sqare, corner 1 is top left, 2 is top right, 3 is bottom left and 4 is bottom right.
If your sqare travel in a direction (45 degre angle) you can :
1- (if you have a relatively small square) trace a single vector (from point 3 to destination passing by point 2) and checking collision against this vector.
2- (for larger ones) 2 vector from point 1 and point 4 going to point 1 and 4 at the destination.
Once you have the collision on the vector, you can then calculate the 'when did it happened' to see if the object would have collided or just cross path ...
TimeCollisionOccured = VectorLengthAtCollision / VectorTotalLength
(Does not really calculate the time but the % of movement completed...)
Gizz
(sorry for any gram. or vocab. error ... still learning english)
Of course, it always depends at how precise you want your collision to be.
Gizz
Bingo! That is the safest and most accurate method. It is even more accurate than a pixel-by-pixel approach because the collision point can be a floating-point coordinate.
Anyway, maybe that was confusing, but have fun anyway.
- Splat
Thank You
Here's a thought though: You can do THIS test before or instead of the vector test, to see if collision is even POSSIBLE. Simply create a temporary bounding box using this concept:
bb.top = min(old.top,new.top);
bb.left = min(old.left,new.left);
bb.bottom = max(old.bottom,new.bottom);
bb.right = max(old.right,new.right);
then test THIS bounding box with your objects...if they aren't in the box, the COULDN'T have been passed through, cause this is a bounding box for the entire area you traveled.
good luck