Archived

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

Collision detection for fast moving objects?

This topic is 6575 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'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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites