Sense collision with certain object

Hi all,

Is there a way to sense collision of one entity with another specific entity (not just any rigid body)?

Unfortunately, not directly through the PlayCanvas API. You have to use the Ammo.js API to set groups and masks. Collision masks / Groups

Edit: Actually, what do you mean by ā€˜senseā€™? As in, how do you know what type of object has been collided with? Or do you want one rigidbody to pass through some but not all other rigidbodies?

The latter @yaustar.

In which case the thread on groups and masks is what you need.

Can you please give an example?

There should be a few examples and explanations in the thread I linked above.

I canā€™t find the link

Works on computer, not mobile, sorry for the trouble @yaustar :no_mouth:

Sorry @yaustar, Iā€™m not quite getting what you said in the thread you looked above. Can you please explain again?

Ah, I was under the assumption that you knew what collision groups and masks are. This page should explain: http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Filtering

All the script is doing in the example of the other thread is setting the filter masks and groups on the rigid body.

Worth noting that PlayCanvas has some pre-defined masks - so donā€™t make the mistake I did and overwrite them.

Ah, yes. I did that the first time too :laughing:

1 Like

Is there a way I can just find the entity by name and check if there is a collision?

Instead of other. rigid body?

Maybe if (result === this.app.root.findByName(//name of entity)

If you want some objects to pass through and not others (which I asked you earlier in the thread), then unfortunately, no.

If itā€™s a case of, ā€œdid I hit a tree or a wall or another car?ā€, then you donā€™t have to worry about physic groups and masks and just use entity tags instead when checking in the collision callback.

Can you send a script showing how to do that?

Ok got it, thanks @yaustar