Hey man. I am trying hard to make simple 2d balls collide and bounce off in a realistic way. I use a mask to get a pixel perfect collision detection, I calculate the collision angle and do some quite extended vector calculations to modify the velocity vectors of both balls to bounce them of. And most of the time my code works. But every now and then the balls just move through each other instead of bouncing off. And I can't find the origin of that "bug". Do you have any experience with physics based, realistic collisions in pygame? Most solutions I found on the internet just use the mask to reverse the velocity vector once a collision is detected. That is effective and seems to work always. But it disregards correct bounce angles. And I really want to have them.
Hi that is a super interesting project and problem you’re having! I made a project to solve for angular momentum and conservation of energy of collisions in non perfectly elastic systems back in college but that was about 7 years ago, I’m afraid I wouldn’t know how to help you with this particular issue of Messing up the collisions I’m sorry!
Hi, not knowing more details about your setup, I’ll try a wild guess which might not be relevant. Sorry if that’s the case. I experienced sometimes similar bugs and it was sometimes due to the high speed of objects versus size of them, so within one frame step it could cross the other object if you were unfortunate (or enough to go through the collision criteria if using centre or rectangle for example). The solution could be to increase FPS and slow down speed for example to keep the physics the same but increase time resolution. Just an idea to test ;)
Great job as usual!
Thanks Dale!! 😁
This is actually sick! I have always found It quite hard to animate characters in pygame.This was super helpful for my games!
Thanks Will!! Glad you liked it 😁
Your videos are great!! I love the content and have been following along with your tutorials to learn python.
Thank you so much I’m very glad you’ve been enjoying them 😊
Hey man. I am trying hard to make simple 2d balls collide and bounce off in a realistic way. I use a mask to get a pixel perfect collision detection, I calculate the collision angle and do some quite extended vector calculations to modify the velocity vectors of both balls to bounce them of. And most of the time my code works. But every now and then the balls just move through each other instead of bouncing off. And I can't find the origin of that "bug". Do you have any experience with physics based, realistic collisions in pygame?
Most solutions I found on the internet just use the mask to reverse the velocity vector once a collision is detected. That is effective and seems to work always. But it disregards correct bounce angles. And I really want to have them.
Hi that is a super interesting project and problem you’re having! I made a project to solve for angular momentum and conservation of energy of collisions in non perfectly elastic systems back in college but that was about 7 years ago, I’m afraid I wouldn’t know how to help you with this particular issue of Messing up the collisions I’m sorry!
Hi, not knowing more details about your setup, I’ll try a wild guess which might not be relevant. Sorry if that’s the case. I experienced sometimes similar bugs and it was sometimes due to the high speed of objects versus size of them, so within one frame step it could cross the other object if you were unfortunate (or enough to go through the collision criteria if using centre or rectangle for example). The solution could be to increase FPS and slow down speed for example to keep the physics the same but increase time resolution. Just an idea to test ;)