Just wondering how you actually define collision masks / groups. I have two characters (with rigid bodies) that I want to ignore each others collision - but still collide with the walls).
The documentation appears a little light, and there are some tantalizing forum posts with links to the answer - that 404, or return to the main forum page.
Any help would be greatly appreciated!
It’s worth noting that the Ammo.js library that PlayCanvas engine is compiled from the Bullet physics engine and therefore the API is the same (the exposed API is actually limited but you can check this in the Ammo.js GitHub repo).
I no longer have access to the code I had before though
I believe you can call setCollisionFlags on the rigidbody which is a bitmask.
Thanks for the reply - but unfortunately that didn’t get me any closer. There is no setCollisionFlags API on the rigidbody.
As far as I can tell - the current method for doing this is with the two properties on the rigidbody property - ‘mask’, and ‘group’ which work together to allow configuration of this behavior. But the documentation is VERY VAGUE.
I managed to get a setup that looks like this:
// NOTE: I consider the first bit (0) to be group 1 for this example
this.entity.rigidbody.group = 0; // Clear out the existing group
this.entity.rigidbody.group |= 1 << 0; // Flip the bit at the first position to true (It's now in group 1)
this.entity.rigidbody.mask = 0; // Clear out existing mask
this.entity.rigidbody.mask |= 1 << 1; // Set the mask for this rigid body so that it collides with anything in group 2
You’ll then need to do this on all objects in the scene that want to collide with each other. Make sure they each are in appropriate groups, so you can filter between them.
Is there a cleaner way to do this? What is everyone’s approach to creating global enums for these kind of purposes? Why isn’t this exposed on the rigidbody component??
Oops. My bad. I forgot to mention that the PlayCanvas rigidBody is a wrapper around the ammo.js’s btRigidBody and to get to it, you have to go
this.entity.rigidBody.data which gives you access to ammo.js’s API (this allows you to make joints etc).
Again, my bad. I completely forgot about this when I did this before in a previous project (https://www.miniclip.com/games/virtual-voodoo/en/).
I used a script to make it easier to configure the groups and masks which you can find here: https://playcanvas.com/editor/scene/568950
You can find the flags I used here: https://github.com/playcanvas/engine/blob/master/src/framework/components/rigid-body/constants.js
No worries - your original post did end up pointing me in the right direction.
Thanks for the additional information - that is very helpful.
Thanks, that helped me a lot.