+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?

in Engine by (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.

by (20,897 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.
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.