schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

Setting body id may be overwriting prior shape. #204

Closed leaf-node closed 8 years ago

leaf-node commented 8 years ago

I set the body id like so:

new p2.Body({"id": 0});

... then added a plane to it, then added another body and shape into the world with body id 1.

When I ran the simulation, the second body fell through the plane. When I set the second body id to 2, the object landed on the plane as expected.

schteppe commented 8 years ago

Yep. If you set the id's yourself, you have do set it for everything. Otherwise all sorts of bad things can happen. Also, the id should be a non-zero integer.

Should write this in the docs. Or just make the ids private.. What do you think? They need to strictly follow these mentioned patterns to work internally in the World.

leaf-node commented 8 years ago

Hmm.. in an ideal world there would be a public getter and a private setter and/or variable. Otherwise more documentation would be very nice.

schteppe commented 8 years ago

Better? https://github.com/schteppe/p2.js/commit/9a275d2ac51f3301d248ac52e7d370921a33d246 https://github.com/schteppe/p2.js/commit/2f8a90f602388a5b1d66fdb9ee6abb2b9b1b8506

leaf-node commented 8 years ago

thanks! : )