Skip to main content
gamedev.net
🔒 Locked

Collision detection problem

Started by Unzip Attack 2 replies 650+ views
Original Post
Unzip Attack
Unzip Attack
Hi , My collision response of my new pool game does work well. After a while testing a bit I found some problems with the collision detection algorithm. If I shoot a ball véry slow in a bunch of balls sometimes (not often) they get stuck in eachother... I think I know what the problem is but can't solve it : first one ball overlaps another ball and has not enough power to "get away" out the other ball. I first solved that with checking whether a ball overlaps or not and setting them to their position 1 step before... Now I see this method doesn't work well because the position before can be taken during one step by an other ball that is moving !! I use for collision detection a standard qt function "Collisions()" which gives all overlapping items... Anyone who can give me some good advice how to solve such problems ? Thanks in advance ! Greetz
Zakwayda
Zakwayda
First, I haven't implemented a system like this, so these are just thoughts, not answers.

Are you using static or continous collision detection? That is, are you a) moving the balls to their final positions and finding if and how much they overlap, and then applying impulses or some other method to resolve the interpenetrations, or b) sweeping the balls against each other to find the first time and point of contact and resolving from there?

If it's the first method, I don't know.

If it's the second, the first thing to do is make sure that you move the ball to just short of the contact time, so that it is not interpenetrating at the beginning of the next frame.

Now, the most accurate approach to the overall simulation is a little more expensive processor-wise, but for a pool game shouldn't be too bad and would be worth it, I would think.

The idea is that you sweep all the balls against each other and keep track of all collisions and the times at which they occur. Keep in mind that a collision will change the balls' velocities, so for any collision, any collisions that occur *after* that may or may not still be valid.

Therefore, you want to find the collision in your collision list that occurs first and ditch all the rest. Back up the simulation to the time of this collision. Apply impulses or whatever to resolve the collision. Start up the simulation again. Rinse and repeat, until dt is used up.

Again, let me stress, I have not done this. This is only based on my current understanding of what's involved, which may or may not be correct. This is something I plan to get to in my own physics code, but I haven't gotten around to it yet.
Unzip Attack
Unzip Attack
The method that i'm using is something like this :

after each 15ms for each ball a global function is gonna be called. In this global function first you check wheter there is a collision with oter balls, you check speed and so on. Also you calculate if there is a collision, what the new movement vector is. After all this, you do something like "moveBy(xVelocity,yVelocity)". 15ms later you do this again and so on...
I think i'll have to make a function which is gonna see "in future" next 15ms if there is gonna be a overlapping...

Anyway thx for you help, it's giving me some new ideas... If anyone has other ideas , there very welcome...

Topic Locked

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

Sign in to reply to this topic.