How to detect a collision?

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

I have a 3D object with a rigid body that has the mode set to kinematic and only moves using global_translate in one direction. It collides with another 3D object that has a rigid body with the mode set to rigid body and moves with translate_object_local. How can I detect the collision through script? I’ve looked up a ton of things and have had no luck. I’ve tried using move_and_collide but it just gave me problems with the collision in the game.

:bust_in_silhouette: Reply From: BraindeadBZH

There is two of doing so, you can either use the signals like body_entered or call get_colliding_bodies in _physics_process.

I’ve tried those before and couldn’t get them to work. Does the script need to be on a certain node for it to work? For example, does it need to be on the object node, RigidBodynode, or CollisionShape node?

ryan329 | 2019-07-26 19:22

For get_colliding_bodies yes, but for the signals no, you can connect the signals using the IDE.

Forgot to mention that you need to contact_monitor set to true and contacts_reported to something greater than 0.

BraindeadBZH | 2019-07-26 19:29

Doesn’t contact_monitor only work with RigidBody2D?

ryan329 | 2019-07-26 19:34

contact_monitor is a property of RigidBody2D and RigidBody, I use it and it works.

BraindeadBZH | 2019-07-26 19:50