View Full Version : Collision detection doesn't like me.
11-22-2003, 10:01 AM
I've been having some problems with collision detection. I made a little document at http://tok.dotsomething.net/problem/ describing it. Any help would be wonderfully appreciated. If you need more information about the problem or my implementation of these objects, just ask.
When you collide against an edge, do you do something like:
velocity.x = -velocity.x;
velocity.y = -velocity.y;
velocity.z = -velocity.z;
If you do, this is what happens: at some point in time the ball will go through the wall - there's no easy way around it. Then, if you're not lucky, which happens very often because you have lots of collisions, the ball will go back into the box but will not quite make it, so it is still outside the wall. Then, it will go even further, so your ball will bounce around infinitely on the wrong side of the wall. Fortunately, there is a way to stop this: If you're hitting the left wall, you do this: velocity.x = float(fabs(velocity.x)); Similarly, if you are hitting the bottom wall, you do this: velocity.z = -float(fabs(velocity.z)); What this does is it forces the ball to go towards the center. However, you will still have some problems at the corners: if you find a solution to this, please post it - for I am doing a demo that has that exact problem (balls bouncing around inside a cube.)
I hope this helps.
11-22-2003, 05:47 PM
This is only a test implementation. The walls can be of any length and at any angle. I'm using a vector reflection about a unit vector normal to the wall to bounce it. The problem is in the collision detection, not the collision response.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.