dimforge / rapier.js

Official JavaScript bindings for the Rapier physics engine.
https://rapier.rs
Apache License 2.0
430 stars 58 forks source link

Support for compound shapes #44

Open BlueNebulaDev opened 3 years ago

BlueNebulaDev commented 3 years ago

I need to create a 2d body made by a circle and a rectangle. According to the documentation on the website I should use a compound collider for this, correct?

I've been looking into how to use a compound shape with rapier2d, but couldn't find much: the "Compound = 8" definition in the typescript source is commented out and there's no constructor or function to handle them.

Would it be possible to port support to compound shapes?

Otherwise what's the recommended way to create my shape?

sebcrozet commented 3 years ago

Hi! You are correct, the bindings don’t expose the compound shapes yet. As an alternative, you can attach two colliders to your rigid-body: one collider with a circle shape, and another collider with a rectangle shape. It will behave the same way as with a single collider with a compound shape.

jacobmott commented 1 month ago

Anyway to request adding support for Compound shapes? Adding multiple colliders works, but then you cant use character controllers since they use a single collider. But your object is now made up of multiple colliders(in my case, 20 colliders). Its seems like without compound shapes, you cant use character controllers.

doppl3r commented 1 month ago

Hey @jacobmott, the Kinematic Character Controller movement function expects a single collider, but you can still attach multiple colliders to the same rigid body and they will translate/rotate with the same rigid body.

For your problem, you could loop through each of your 20 colliders, then conditionally compute the movement using the same controller.

In general, I recommend using 1 of the colliders for your controller movement, and the other 19 colliders for events.

jacobmott commented 1 month ago

Hey @doppl3r , Thanks for the reply. That sounds interesting, ill give that a shot and see how that works out.