erincatto / box2d

Box2D is a 2D physics engine for games
https://box2d.org
MIT License
8.26k stars 1.54k forks source link

Add an option to make ChainShape two-sided #638

Closed jube closed 4 years ago

jube commented 4 years ago

In #607, ChainShape was made one-sided. This behavior is not really backward compatible with previous versions of Box2D. I wonder if it may be possible to add a feature to have a two-sided ChainShape.

The documentation only says that if you need a two sided chain, you can "create a bunch of two-sided edge shapes". Would it be possible to automate this process in ChainShape? Currently, what I'm doing is create a first chain, reverse the points and create a second chain, but I feel it's not really a good solution.

erincatto commented 4 years ago

It is not backwards compatible. This was unavoidable because smooth collision does not work with two-sided collision. If you want two-sided collision you have to give up smoothness. If you still want two-sided collision use edge shapes: https://github.com/erincatto/box2d/blob/47b1bfa13338c9322c77b70c9058b236d02fd046/include/box2d/b2_edge_shape.h#L43

Using back-to-back one-sided collision has undefined behavior and will not be automated.