pmndrs / p2-es

JavaScript 2D physics library
https://p2-es.pmnd.rs
Other
123 stars 11 forks source link

Improve handling of adding and removing objects while stepping #130

Open isaac-mason opened 10 months ago

isaac-mason commented 10 months ago

If an object (body, constraint, spring) is added or removed from the world while the world is stepping, an error is thrown.

Developers need to work around this by scheduling changes to run after the step.

Can we improve this? e.g.

isaac-mason commented 10 months ago

Change for deferring addition/removal of objects while stepping is in next: https://github.com/pmndrs/p2-es/commit/eabee3fefd9f3c88869260b68e8d9bcd1f15c756

isaac-mason commented 7 months ago

For the moment the change for deferring addition/removal of objects while stepping has been reverted: https://github.com/pmndrs/p2-es/commit/46f179eb8e03c6fc71dc4ca6eb4eba1fe2762810

I'm not confident it was the best approach. The ideal solution is to make changes to support adding bodies during a step. e.g. cannon-es does not have this limitation, we should check how it handles this.