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

28th Jan 2019, 5:25 AM
Abhishek kumar
Abhishek kumar - avatar
4 odpowiedzi
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! 😁
28th Jan 2019, 10:22 AM
James
James - avatar
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. 🙁
28th Jan 2019, 10:38 AM
James
James - avatar
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 .
28th Jan 2019, 10:43 AM
Abhishek kumar
Abhishek kumar - avatar
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.
28th Jan 2019, 10:58 AM
James
James - avatar