+1 vote

i have tried using area with a collision object, but this only detects if another body/area enters the area. if the npc is already in the sphere that represents the noise, there is no entered event once the noise is triggered. i have tried disabeling and enabeling the noise area, but this does not trigger the hearing area. does anyone have any idea how this could be done?

in Engine by (16 points)

1 Answer

0 votes
Best answer

Use $Area2D.get_overlapping_areas() to get an array of all overlapping areas. And use $Area2D.get_overlapping_bodies() to get an array of all overlapping bodies. Hope that's what you meant, also you can hold the control key and click on almost anything in the script editor to see its documentation.

by (659 points)
selected by

thanks, this seems to be what i am looking for. although i work in 3d there are similar functions. however i don't understand how i can get this to work. the area function requires a collision mask. collision masks are only available for rigid bodys and so on, not for collision shapes. a collision shap however is the node that defines the area of the area node.

so: my area not has a child that is a collision shape. but this needs to be a collision object? how can a collision object define the area of my area node?

You have to set the collision mask of the area itself. The area also has to have a collision shape as a child to determine its hitbox.

thanks. it is working now. some area was set to disabled.

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 Frequently asked questions and 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 [email protected] with your username.