Using same collision mesh for collision detection and actual collision physics?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi All –
Could be a dumb question but is there a way to use the same collision mesh node for both: Area node’s collision detection and actual physics body collision?
Having to duplicate each collision mesh to use it for those distinct purposes is a performance killer …

:bust_in_silhouette: Reply From: Zylann

Shape and its derived classes are resources. Resources can be shared, so you can assign it to multiple CollisionShape nodes (i.e share it). You will need to create it only once and reduce memory usage, but it will cause twice as much processing in any case (just like it will if you have 10 nodes with the same shape).

I’m not sure what you expect to do in this situation, because if you have an Area and a Body with the same shape, in the same position and same collision masks/layers, they will basically trigger the same events at the same time redundantly, and will indeed be a waste. Better just listen to events from the body and not use an area (if they are configured the same).

OK, I may be getting this whole thing wrong then but what I thought was that in order to get a collision to trigger an event you need to use an area node with a collision shape. When a body or something else enters said area, a signal is sent to a script and a function is triggered.
BUT, a collision shape attached to an area node that sends signals does not work as a physical collider (for rigid/vehicle/etc bodies to collide with, bounce off and so on). I need another collision shape for physical collisions.
Ie, if I want a rigid body to trigger a func when it hits a brick wall (static body) but also want that rigid body to bounce off of that wall, I need that wall object to have 2 collision shapes, one for area (signal) and one for collision.
Or it that not true and I can somehow use one collision mesh for both purposes?

Macryc | 2020-02-11 20:22

Bodies emit events too when then enter in contact with other things: RigidBody — Godot Engine (3.2) documentation in English

You would need an extra area only if you want to detect things within a different shape.

Zylann | 2020-02-11 20:29

Hmm, so how do you detect collision of a rigid body with a static body? I tried:connect("body_entered", self, "_what_happens_on_crash")
I attached it to the rigid body. What happens function was also in the same script. In that function I said: if == “obstacle”: print sth. I then hit the rigid body into the obstacle object but the signal didn’t work…

Macryc | 2020-02-11 21:04

In the RigidBody inspector, enable Contact Monitor, and set Contacts Reported to at least 1.

Zylann | 2020-02-11 21:09

I am glad I asked the question. I’ve now removed so much redundant collision geometry from my level and performance is through the roof!

Thank you!

Macryc | 2020-02-12 06:24