Collision Detection for fast moving objects - Appropiate Response?

Started by
6 comments, last by Azaykon 18 years, 10 months ago
In oliii's PollyColly tutorial, he presents a method for finding out based off of an object's velocity whether an object will collide forward in time. A positive number is returned if such a collision in the future is detected. This is supposed to be useful for fast moving objects that might teleport through an object if said moving object is moving too fast. My question: Once you know that such a collision ahead of time is going to happen, what is the appropiate response? As far as I can tell, you cannot change the object's position the advance frame in which it is detected because it is still in front of the object, so that means you have to take whatever measure needed the frame after it passes though? Would you have to send some kind of signal to the moving object to leap back right infront of the object the frame after? That would seem really messy. Any ideas would be appreciated.
Advertisement

Once you know that a collision will happen at some point in the future you should determine at what time Tc that collision will happen.

Generally this is important if time Tc is between the current time and the time of the next likely update. In which case the collision would happen and then the update would occur - causing a possible pass-through.

Once you know the time Tc at which the collision will occur you can subtract the current time, T0 from Tc to determine t0, the time until collision. More importantly however you can determine t1, the amount of time between the point of impact and the time T1 of the next update.

T0 = current time;
T1 = next update time
Tc = T0 + t0; // collision time
t1 = T1 - Tc;
t0 = Tc - T0;

Once you know t0 and t1 you can determine that the object will be traveling for t0 and will then collide with objectB. At which point it will respond to the collision by chaning velocity - likely both speed and direction. From Tc until T1 ( a time of t1 ) the object will be traveling at a new speed in a new direction.

Distance is of course velocity X time. So if you know the duration of time which the object will be traveling AFTER the collision, but BEFORE the next update, then you can update the position of the object based on the new velocity.

The overall effect is that you will be x1 distance away from the wall/object after a single update, and after the next update you will be x2 distance away from the wall, traveling in a new direction.

v1 = velocity of object before impact
v2 = velocity of object after impact
x2 = x1 + ( v1 * t0 ) + ( v2 * t1 )
Jeromy Walsh
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Once you have the time of collision, you can integrate twice: once before the collision (with the first time interval), then solve the collision and then integrate again with the remaining time. Of course you must do this for both colliding objects.
I think I may not have explained the problem clearly. So I will utilize pretty pictures:



So, the problem here is that objects that are moving too fast can slip through other objects, given high enough velocity. If I detect however, that a collision would have taken place inbetween frames, what is the appropiate response?

EDIT: If it makes any difference, I just realized that objects could possibly completely change direction suddenly from one frame to the next.

[Edited by - load_bitmap_file on June 10, 2005 3:34:51 PM]
One thing you can do is find out where the object will collide. Since you really don't know when the next update will be but you do know that regardless of when that comes the object will be on the other side of the object you can move the to where it collides with the wall, then if need be change the object's direction as if the collision has already taken place. Another thing you might do is check for where it's previously been versus where it is now and then find the collision and do the direction change. This way you don't have to worry about when the next object update will take place because it will correct itself.

Essentially you want to make a collision volume that covers the area between both frames, then test where that volume collides with the wall. Once you have that point you set the objects position there. In your drawing you use a sphere versus a plane. A good volume to use is a cylinder where the radius of is is that of the sphere, the top and bottom circles are normals are the direction from the current point to the future point. You might also want test the future sphere as well.

I hope this helps, fast collisions can be tricky to deal with.
-----------------------Or, as I put it, MMORPG's are currently about attaining two primary things: strength and a shovel. The rest is you just shoveling sh** endlessly trying to get stronger to shovel more sh** so you can look for the next new shovel to shovel more sh** with. Once you are done, you can stand on top of a large pile of sh**, raise your golden sh** shoveler up high into the air and boast how proud you are to be the best sh** shoveler of them all. -Griffin_Kemp
You can test both the object, and like the post above, the velocity + object, if it's going that fast.

However, if your moving an object 1000 pixels a frame, thats kinda too fast I would say.

If it's so fast in the game you can't see it, then don't draw it, and just do it how counter strike and other machine gun like weapons do it.

also try advoid using sqrt with c. rumor has it it uses some search routine and a lookup table, so it's rather slow :(
Black Sky A Star Control 2/Elite like game
Quote:Original post by load_bitmap_file
In oliii's PollyColly tutorial...

Would anyone here happen to have a link to the tutorial? I am interested in reading it now...
Here is the link to some of his code examples, Moe:

Here

You will find it under: 2D swept+overlap polygonal collision and response

This topic is closed to new replies.

Advertisement