1. 6
posts
Registered User

## Ball collision reaction

hi, I have been using a script to make multiple balls have random movement and collision, there is a problem though, which is that sometimes two balls end up rotating around each other and stick together.
Last edited by tommyYYY; July 31st, 2008 at 02:45 PM.

2. Same kind of thing used to happen when i was working out a custom sweep test. And to fix it at that time, i had just added .50 to the final updated position for eg:
ball0._x = (ball0._x + pos0F.x)+.50;
ball0._y = (ball0._y + pos0F.y)+.50
I know its not technically sound, but i couldnt figure out what was wrong with the code. But latter on i did fix the code. And i went through the code right now, but i cant remember how i fixed it!!!
Last edited by acebuddy29; July 31st, 2008 at 01:29 AM.

3. 6
posts
Registered User
Originally Posted by acebuddy29
Same kind of thing used to happen when i was working out a custom sweep test. And to fix it at that time, i had just added .50 to the final updated position for eg:
ball0._x = (ball0._x + pos0F.x)+.50;
ball0._y = (ball0._y + pos0F.y)+.50
I know its not technically sound, but i couldnt figure out what was wrong with the code. But latter on i did fix the code. And i went through the code right now, but i cant remember how i fixed it!!!
thanks for the reply, but it doesn't really solve the problem, cos the +0.5 is even less accurate than estimation, it's more like an assumption. i think there should be a way to + or - depends on the position right?

4. thanks for the reply, but it doesn't really solve the problem, cos the +0.5 is even less accurate than estimation, it's more like an assumption. i think there should be a way to + or - depends on the position right?
See Technically you shoudnt even have to have a seprate system to do this. I mean this shoudn't even happen. Well when i sweep test collision, what i do is find the 1st point of contact and then change the value of the ball to this point of contact. for eg: if 1st point of contact.y = 200, then ball._y = 1st point of contact.y. And at this point the ball should not detect any collision and bounce off. But sometimes, the ball still detects collision at this point too, i.e: 200. There can be a lot of reason why this could happen, things like, if u put ur collsion detection before updating the ball's velocity, u might get a totally different effect. Or it could be because of how flash can be inaccurate when it comes to .5 pixels. adding +.50 pixel might get the ball sufficiently out of a collision. Its ofcourse just a work around. I'll trying running your fla and see if i can do anything.

5. 117
posts
Registered User
I could not observe the problem in your demo, but collision solving frequently causes such behavior if you solve each local collision one by one. What happens is that the solving of a collision causes another collision which won't be caught by the system (you can iterate the collision solving process several time, that often is good enough to avoid such behavior). The only way to prevent this (and not only circumvent it somehow) is to use a roll-back kind of collision solver, which searches for the earliest collision in the current time frame and puts all objects back to that time, solves the collision and carry on with the simulation until the next collision happens.

So, depending on the application of your collision solver, you might want to try iterating the solving process or you have to rewrite the system. If you aim at a pool-style of game, I highly recommend using a roll-back solver (I wrote a game last year which employs such a solver, if you're interested, have a look)

6. 6
posts
Registered User
Originally Posted by acebuddy29
See Technically you shoudnt even have to have a seprate system to do this. I mean this shoudn't even happen. Well when i sweep test collision, what i do is find the 1st point of contact and then change the value of the ball to this point of contact. for eg: if 1st point of contact.y = 200, then ball._y = 1st point of contact.y. And at this point the ball should not detect any collision and bounce off. But sometimes, the ball still detects collision at this point too, i.e: 200. There can be a lot of reason why this could happen, things like, if u put ur collsion detection before updating the ball's velocity, u might get a totally different effect. Or it could be because of how flash can be inaccurate when it comes to .5 pixels. adding +.50 pixel might get the ball sufficiently out of a collision. Its ofcourse just a work around. I'll trying running your fla and see if i can do anything.
At first, i also thought in the perfect situation, the late detection shouldn't even happen. but in real world, i think it does happen sometimes.

sorry that my mindset is very rigid, my mind still tells me that there must be a way to calculate the time and position that collision point 'should be detected' and the point that it is actually detected'. and reverse x y position back to the point of time it 'should be detected'.

7. 6
posts
Registered User
Last edited by tommyYYY; July 31st, 2008 at 02:45 PM.

8. try searching for sweep collision test on google . Let me knw if u need more help on that.

9. 6
posts
Registered User
Originally Posted by acebuddy29
try searching for sweep collision test on google . Let me knw if u need more help on that.
Hi, thanks. i am an idiot, actually in my real application, because the object dimention changes dymamically which causes the problem, i have find a way to solve that, actually my pos0.x += vel0.x/absV*overlap; pos1.x += vel1.x/absV*overlap; works fine. not a collision problem.

10. 6
posts
Registered User
For people who face the problem, can check out the post i wrote: Flash Ball Collision Prevent Stick and Rotate
Last edited by tommyYYY; July 31st, 2008 at 02:38 PM.

11. tommyYYY
do I have permition to use your code?
that would be a great help

ps: nice work
_global.tommyYYY.fans.push(this);

12. Hey good you figured it out. But the example .fla file that you had put didn't have dynamic dimensions or did it? Anyways nice Tutorial