schteppe / p2.js

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

new p2.Shape({ material: ... }) not documented #215

Closed AndrewRayCode closed 8 years ago

AndrewRayCode commented 8 years ago

According to the source code, you can pass in a material to the constructor of a shape.

this.material = options.material || null;

However this isn't mentioned in the shape documentation.

Also the friction demo doesn't take advantage of the material in the Shape constructor:

var slipperyShape = new p2.Circle({ radius: 0.5 });
slipperyShape.material = new p2.Material();

Additionally, why did you choose to put the material on the shape instead of the body (like Cannon does it?)

schteppe commented 8 years ago

You're right, this should definitely be documented and brought more into the light. Thanks for the heads up.

If you look closer you see that Cannon.js has support for both per-body and per-shape materials. The reason why I added per-shape materials to Cannon is that I wanted to enable workflows like in Unity, where you specify friction and restitution per Collider Component. And also because Box2d has it. I believe per-shape is the way to go, because per-body is more limiting.

schteppe commented 8 years ago

Turns out it was already documented. However, I made the demos use the constructor option. Much cleaner. Thanks.