The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

I'm trying to detect if any object is colliding with a specific area2d I'm using as a hit box. Currently I'm just using is_colliding, however I keep getting an error:

Invalid call. Nonexistent function 'is_colliding'

Yet I see is_colliding used in example tutorials all over the web, and the only difference I can see is that they're attaching it to a kinematic character2d. Can this be used with area2d? Is there a better way? Here's my code:

extends Area2D

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    if(get_node(".").is_colliding()):
        print("Collision!")
in Engine by (30 points)

no need to use get_node("."), since you're already in the object you can use self.is_colliding(), or even simply is_colliding().

1 Answer

+3 votes
Best answer

Areas are not 'colliding' because they are not 'physical objects'. Instead a body or an area can ENTER or EXIT a certain area.
You should use corresponding signals to react. You can connect to the signals on the signals tab or from within the code.

in such case the code would be (for a default Area2D):

func _on_Area2D_body_enter(body):
    print(str('Body entered: ', body.get_name()))

A specific body can be detected easily with the help of groups:

func _on_Area2D_body_enter(body):
    if body.is_in_group("player"):
        print(str('Player has entered')
by (172 points)
selected by

The body that needs to detect the area could have a child area for overlap detection too.

Sometimes is better to have a sub-structure that is functional to a specific purpose (but is a design decision).

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.