0 votes

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?

Godot version 3.2.3
in Engine by (91 points)

1 Answer

0 votes

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.

by (293 points)

No, I don't need to "activate" something, I need them to have collision between them. Area2Ds don't do that.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.