Checking if an area 2d is colliding with an physicsbody

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By trien


how can i check if an area2d is colliding with an physicsbody(static,kinematic and rigid) in the body_entered signal

:bust_in_silhouette: Reply From: haydenv

The body_entered signal will be generated by the Area2D node whenever a PhysicsBody2D node enters the collision shape of the Area2D node. You will need to connect the Area2D node’s body_entered signal to the function that you want it to trigger. The triggered function will be passed an argument (the PhysicsBody2D node that entered the area). So make sure the triggered function has a single parameter (see code snippet).

func on_Area2D_body_entered(body):
    # Put here the code you want to run whenever a body enters the area.
    # Remember that 'body' will be the PhysicsNode2D that entered the area.
    print( + " entered the area")
    print("velocity " + str(body.linear_velocity)) # assumes body is RigidBody2D, since KinematicBody2D and StaticBody2D nodes don't have a linear_velocity property

Remember that I had to connect the Area2D node’s body_entered signal to this function, and that this function could be in the Area2D node or it could be in any other node. For information about connecting signals to functions I recommend the signals tutorial contained in the docs. Also, feel free to ask additional questions.

That makes sense Iam totally stupid
Anyway thx

trien | 2022-04-30 10:14

You’re welcome

haydenv | 2022-04-30 10:51