🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Collision detection for fast moving objects?

Started by
7 comments, last by Zenroth 24 years, 6 months ago
what?
William Reiach - Human Extrodinaire

Marlene and Me


Advertisement
I'm going to guess your problem is when something that moves really fast moves through an object that it should be colliding with, right? If not, go ahead and stop reading now

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

Yes that is what i mean the object moves so fast it passes through the other object. A good example would be a pong gamewhere the ball gets so fast it goes through the paddle.

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.

Hi,
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)

Hmm i havnt really done much with vectors. So im not quite sure how to implement something like that i guess it would be as simple as basicly generating a line and doing a collision check. The problem though would be then knowing if the object passed through the obstical. Or maybe im just confused.
That's why you have to check if at this precise moment, your 2 object did collide or merely cross path.

Of course, it always depends at how precise you want your collision to be.

Gizz

You can have perfect precision without having to do a check every pixel or two by using the above method. Basically, you "draw" a line from the previous position to where the box should be now based on its velocity. Then, check to see if any surfaces of obstacles intersect that line. If they do, the intersection point is the EXACT point where they collide. Figure out how much time has elapsed between the moment of collision and the current time (basically take the length of the "line" you drew past the point of collision and divide by the velocity). Now that you know where the collsion took place and how much time has elapsed since, you process the collision however you want, and then move the object with the newly calculated velocity using the previously calculated time delta after the collision.

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

I need to know how to do collision detection for high speed objects(im still using boundying boxs). I belive what i need to do is step through them as if they were only moving 2 or 4 pixels at a time and do collision checks. Instead of 16 or more pixels. The problem is im not sure how to implement this.

Thank You

The vector idea is correct. Although I feel that the 2 vector system mentioned isn't realizing it's only right for movement in certain directions...a 4 vector test is the only way to be sure you don't intersect without considering what type of movement you have.
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

This topic is closed to new replies.

Advertisement