How to make a KinematicBody2D collide with two different layers differently

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

So, I have this KinematicBody2D, an NPC, and they’re supposed to collide with other NPCs (with the same setup) at a greater distance than with the world.

I have it set up that I have a CollisionShape2D as the KinematicBody2D’s child, with the width set up to correctly collide with the things in the World collision layer.

I have then given that KinematicBody2D a StaticBody2D as a child, with a CollisionShape2D with a greater radius, and put that StaticBody2D’s collision layer and mask to the NPC Space layer. However, that doesn’t work, the NPCs don’t collide with each other based on that NPC Space detecting StaticBody2D, only based on the World layer, which they’re also part of.

Is there a way to make them collide with objects in different layers using different CollisionShape2Ds?

:bust_in_silhouette: Reply From: SnapCracklins

Area 2ds are better for detection than StaticBody, as StaticBody are meant to be non-moving objects. I would try using an area AND a body, then you can just wait for signals on each.

for instance, on the Area2D:

signal NPC_can_be_activated

func on_body_entered(player):
         if body.name == "player"
             ### whatever logic here
                     emit_signal("NPC_can_be_activated")

Then just put that on both and tie the input that triggers the NPC to not respond unless the signal has been called.

No, I don’t need to “activate” something, I need them to have collision between them. Area2Ds don’t do that.

mymokol | 2022-04-16 19:57

Same problem in Godot 4 and no solution in sight.