Skip to main content
gamedev.net
🔒 Locked

Collision Detection problem

Started by slyprid Jun 4, 2006 at 4:23 PM 3 replies 1k views
Original Post
slyprid
slyprid
I'm writing a program for my college class, and it involves taking an object and bouncing it around the screen. Well the problem i'm running into is that some of the objects tend to stick or orbit around each other and than eventually break free. Is there any solution to help prevent this? Let me know if want to see some code. Thanks for your time. Slyprid
Guru2012
Guru2012
I'm going to guess that this happens because you do something akin to calculating collisions whenever two objects overlap. Correct me on this if I'm wrong.

The problem happens when the two objects collide, but do not separate during the next timestep, so then a collision is detected on the objects which are separating, and the result of your calculation reverses the objects' direction, causing them to stay overlapped during your next timestep, and so on. This is not a problem with your formulas or collision detection.

There are several ways to fix this. When I got this problem with a pong game, I had my collision detection throw out separating objects. For example, if you are using spheres, only report a collision if two spheres are headed towards each other.
slyprid
slyprid
That sounds like what might be happening. Let me try a couple things real quick and will post again if anything works. Thanks.

Slyprid
nef
nef
If you are having the problem where they are overlapped and you change their directions, but they remain overlapped, there is a pretty quick fix for that.

Each frame when you do your collision check, don't check to see if they overlap, but check to see if they will overlap the next frame.

For instance, you have one ball moving forward and it's about to hit another ball. If you have their direction and velocity then you can calculate their next position, then do the collision check on that position. If they collide, reverse them to prevent anything from ever going into an object in the first place.

The last problem i can think of is if your balls move so fast they just pass through each other. This will happen i think when your velocity is greater than the size of the diamater of the sphere. I dont remember the exact math behind this but i know if you have the position of the ball one frame and its velocity and direction, you have a line segment that you can use to test the other ball's line segment with and see if they overlap, that will tell you if they collided and should even catch the very fast cases, hopefully someone else can elaborate or has a better idea. But i think your problem is just the checking if they intersect now insted of will they intersect.
slyprid
slyprid
Thanks, the idea of checking the frame ahea worked. Some of the faster moving objects you can tell collide a little early, but all I have to do is lower the speed random some and it looks great. Thanks again.

Slyprid

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.