Hello, is it possible to make RigidBody2D disappear upon hitting a Kinematic2D?

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

I have connected the signal to my RigidBody2D GDScript. But every time it detects the Kinematic2D, it is my Kinematic2D that disappears.

:bust_in_silhouette: Reply From: GlitchedCode

What you want:
RigidtBody2D object to disappear when touched by KinematicBody2D

Problem:
KinematicbBody2D is disappearing

Assumption:
You are connecting the body_entered signal from the rigidbody to the rigidbody

Solution:
These bodies never actually enter eachother since they collide and touch only. What you want to use here is an area2D on your physicsbody and give your area a collisionshape that is a little bigger than your initial collision box. This area holds the signal we want to use to achieve this, body_entered. An area can not collide with a physics body and so a physics body is able to enter the are and trigger the signal call. From here you are able to do whatever it is you want to do with your checks or to the body that enters the area/collides. Some examples may be:

if body.is_in_group("group name")

or

if body is RigidBody2D

or

if body.name == "object_name"

Once you have confirmed this is the physics body you want, you can make your body disappear with something like:

body.queue_free()

to delete it or

body.visible = false

to hide it. Keep in mind that while invisible, it can still be collided with so you may also want to set its collisionshape to disabled.