Page 1 of 1

Weird collision bug?

Posted: Mon Feb 04, 2013 8:38 pm
by bugmang
I have a simple simulation where I have a ball (with a sphere shape) moving around that "can" collide with multiple obstacles (each is a square and are static with infinite mass so they don't move when the ball collides with it). I simply assign the ball a velocity and let it bounce wherever infinitely. Simple right?

The attached image illustrates the problem I'm having. The red line indicates the ball's current trajectory and the blue line indicates the trajectory after collision. The top part of the image illustrates the expected behavior (which I get most of the time... or at least what appears to happen). The bottom part of the image shows the odd behavior that occurs sometimes (and it's visually surprising). In other words, It reverses direction entirely rather than simply reversing the y velocity. I read that I could combine these two objects into one body but sometimes they are combined as part of a non-convex shape (like a "C"). Is there a simple fix that I'm overlooking? I'm new to chipmunk... Thanks!
Expected behavior shown at top, odd behavior shown at bottom.
Expected behavior shown at top, odd behavior shown at bottom.
collision.png (13.54 KiB) Viewed 5874 times

Re: Weird collision bug?

Posted: Tue Feb 05, 2013 3:08 pm
by slembcke
So one issue with the way collisions are handled in Chipmunk is that you can hit the "cracks" between shapes even if they are perfectly flush. What's happening is that your ball is hitting the corner of the block on the right, and that collision is being handled before the flat edge of the one on the left.

Using smaller timesteps will help, but the best way to fix it is to join your collision shapes together to avoid the cracks.