Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i detect a collision of kinematic body 2d and area 2d

Tags:

godot

I am trying check for a collision with the kinematic body 2d and an area 2d. I can't seem to find the function to do that.

like image 338
Vlad Ivanov Avatar asked Jul 08 '26 02:07

Vlad Ivanov


2 Answers

First of all, both objects need a collision shape. You can then detect if the Body enters the Area with the function _on_body_enter.

like image 91
magenulcus Avatar answered Jul 10 '26 17:07

magenulcus


Collisions are detected automatically, but you can code what your Area2D will do when the body enters its collision shape. Attach the script to your Area2D scene go to the node menu (part of the editor, where signals and groups are). Connect body_entered signal to itself. This will create a function in your script, which will be called every time, collision happens.

func _on_Area2D_body_entered(body):  # _on_NodeName_body_entered(body):
    pass

You can give that function your own name while connecting the signal in the editor. You can also connect signals in your script using connect() function. More about it here.

like image 36
Andrey Kachow Avatar answered Jul 10 '26 17:07

Andrey Kachow