+1 vote

I'm making a 2d game which requires me to make a laser gun. I've got it mostly working, but is there a way to disable an Area2D and make it so that other Area2D's don't recognize it in the area_enter signal?

asked Aug 11, 2018 in Engine by TheMadScientist1234 (19 points)

1 Answer

+2 votes

There are two main approaches to this problem:

1) Using the collision layer system.

Assign the area to a layer, and then set the other areas to ignore that layer in their layer mask.

See this page for an introduction to how collision layers work.

2) Using groups.

Put the area in an "ignore" group (use whatever name you like. Then in the other areas' area_entered code, use if area.is_in_group("ignore") to test for the group.

Option #1 is the preferred solution, because this way the engine isn't even testing collisions between those areas because they can't "see" each other and you don't need to write any code to make it work.

answered Aug 11, 2018 by kidscancode (6,456 points)

1 won't work due to https://github.com/godotengine/godot/issues/7644, your best option is to filter I guess, or use another area as hitbox.

Thank you so much! This worked perfectly!

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.