0
Why some of the created bubbles get stuck in the boundary condition ?
I had made a program which produces 50 bubbles on random width & height of a canvas also these bubbles changes color when they collide with the edges of that canvas and when a bubble collide with its colleague bubbles they both changes their position . But , when they collide some of the bubbles get stuck on their boundaries rather than change their direction provided . https://code.sololearn.com/WXxvFQlmaQiN/?ref=app https://code.sololearn.com/WXxvFQlmaQiN/?ref=app
4 Respuestas
0
So, you want the bubbles to bounce off each other in a natural way, rather than simply rebounding in the exact opposite direction, because that makes them get stuck...? I will investigate this for you.
Cool code! 😁
0
Ok, I think they get stuck when two balls travelling in the same direction collide. The balls change direction, however they still both go the same direction as each other, and then they immediately collide again. This doesn't happen in real life.
Maybe write something like... if same direction, only one ball changes direction upon collision.
EDIT: Nope... I tried that and they still get stuck. 🙁
0
okay brother .. But I did not think this is the problem cause the collision function only checks for the distance b/w this.r + other.r there is no scope for same direction or likewise anything regarding this .
0
I am now thinking that they get stuck because they overlap too much before changing direction, so that the collision function gets triggered again because the condition is still true.