vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
404 stars 48 forks source link

Resolving multiple simultaneous collisions #33

Closed codinghands closed 9 years ago

codinghands commented 10 years ago

I'm having issues where a shape collides with multiple shapes in one update. shape:neighbours() looks like a good candidate to help here, but in the collision callback I've set up none of the objects have anything in the neighbours table. Is there any way to get all collisions in a single update for easier handling?

For example, if a ball hits 2 blocks, the MTV is applied to the ball to move it, but I need to wait until all of these movements are complete until I invert the ball velocity. I believe using the 'stop' callback is insufficient as by this point the objects have moved at their old uninverted velocities, and are again colliding.

vrld commented 10 years ago

I'm having issues where a shape collides with multiple shapes in one update. shape:neighbours() looks like a good candidate to help here, but in the collision callback I've set up none of the objects have anything in the neighbours table.

Can you provide some minimal code example where this (neighbors() being empty in the collision callback) happens?

Is there any way to get all collisions in a single update for easier handling?

There is no good solution to the problem since resolving one collision can solve or introduce another. Anyhow, you have basically two options: