How to detect incoming colliding objects if the collided object is a Rigidbody2D

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

More specifically, is there a way to get properties of colliding RigidBody2D through the lens of the collided RigidBody2D?

One solution that will not work is using body_entered(body) signals. There will be multiple instances of colliding RigidBody2D objects (Planets) that will collide against the collided object (Player) and does not make sense for multiple colliding RigidBody2D objects (Planets) to emit their properties to the collided object (Player).

There is also the issue that it is awkward for collied RigidBody2D object (Player) to expose properties using signals when there are multiple instances of the colliding RigidBody2D. For example, I may want to make the Player object send his properties to a single Planet object instead of all instances of the Planet object. However, with connecting signals through code, it will ensure that all instances of the Planet object will get the signal since it will share the same script.

All these problems should be solved if there is a way to get the properties of colliding objects through the collided object but RigidBody2D’s body_entered(body) does not fire when the signal is emitted to itself unlike Area2D’s body_entered(body). Any work around for this is greatly appreciated. Thank you.

:bust_in_silhouette: Reply From: tastyshrimp

According to the docs the RigidBody2D should react the same way as the Area2D in terms of collisions but you need to turn the contact_monitor to true, which is false by default.

You should also check the CCDMode to see if it is set to the appropriate value for your game.

Ah you’re correct! But I also had to increase contacts_report to 1 to hold contact information and that did the trick! Thank you.

danii956 | 2019-12-17 19:51