Hi,
I am working on a game which has a character with pet. The pet follows player and has a rigidbody component attached to it. I want to avoid collision b/w player and pet. Is there any quick way for that?
Hi @Hassan_Amjad1!
I assume both entities have a dynamic rigidbody and you don’t want to have any physical reaction between those entities for some reason?
I’m afraid this is not easy to achieve, but you can search on the forum for collision mask
or collision layer
to find some suggestions.
Maybe it’s an option to use a parent entity with a rigidbody and compound collision, but I’m not sure if this is possible in this case. You can check the page below for more information.
As Albertos mentioned, you need to use collision group and masks:
You can search the related topics on the forum, or refer to chapter 5 of the Bullet physics manual:
Hi,
Did this to avoid collision b/w two rigidbodies but they can collide with every other rigidbody.
var body = this.entity.rigidbody;
// Groups
if (this.isPlayer) {
// Assign the player to group A (USER_1)
body.group = pc.BODYGROUP_USER_1;
// Set the mask to collide with everything except group B (USER_2, which is the pet)
body.mask = pc.BODYMASK_ALL & ~pc.BODYGROUP_USER_2; // Mask out the pet's group
}
if (this.isPet) {
// Assign the pet to group B (USER_2)
body.group = pc.BODYGROUP_USER_2;
// Set the mask to collide with everything except group A (USER_1, which is the player)
body.mask = pc.BODYMASK_ALL & ~pc.BODYGROUP_USER_1; // Mask out the player's group
}
Feel free to ask incase of any confusion.
Thanks