How do i detect collision with my bullet?

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

my bullet is an area 2d node with it’s own scene. It is being instanced in my main scene, which has a kinematic body 2d with a collision shape 2d that i want to detect the collision with. All the collision tutorials i see, have used areas and signals. The problem is, I’m not using an area (except in the bullet, which isn’t the node i want to detect with,) and that the bullet is only instanced, so it’s hard to connect the signal with it. How do i do this?

:bust_in_silhouette: Reply From: Bernard Cloutier

I’d suggest adding hitboxes to your kinematic body 2d, and by hitboxes I really mean an Area2D node. Then connect your hitboxes’ body_entered signals to your KinematicBody2D’s script.

Using areas is the preferred way to do collision detection.

ok, so it’s common to have an area 2d node along with a kinematic body 2d?

Millard | 2020-10-02 18:55

ok, so i did what you said, but the kinematic body isn’t detecting my bullet. It’s totally ignoring it. I connected the kinematic body 2d’s area 2d nodes area_entered() signal to the kinematic body 2d, and none of the code i’ve written under the signal code is working. any ideas?

Millard | 2020-10-02 19:17

Yup. The only collision detection that KinematicBody exposes is in the move_and_collide function. Although those collisions are intended to be used for movement logic.

Separating the physics collisions (movement, forces) from the gameplay collisions (area triggers, custom logic) is good practice as well.

Bernard Cloutier | 2020-10-02 19:17