The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 12 of 12

Thread: Ball collision reaction

  1. #1

    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. #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. #3
    Quote Originally Posted by acebuddy29 View Post
    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. #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. #5
    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
    Quote Originally Posted by acebuddy29 View Post
    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. #7
    Thanks for the reply.
    Last edited by tommyYYY; July 31st, 2008 at 02:45 PM.

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

  9. #9
    Quote Originally Posted by acebuddy29 View Post
    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. #10
    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. #11
    tommyYYY
    do I have permition to use your code?
    that would be a great help

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

    "A human can interpret missing logic but a computer can't." - wkt
    "That goes into the 'too bad' box." - TOdorus
    "This is a three year old thread, there's no reason to post here..." - flyingmonkey456
    "Despite beeing the oposite, they look very similar to me." - SparK

  12. #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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012