I'm using the Area2D's CollisionShape2D within the KinematicBody2D scene2 as player, so I'm struggling using _on_Area2D_body_entered() and _on_Area2D_body_exited() to detect the Area2D's CollisionShape2D of the StaticBody2D.
awful code:
func _on_Area2D_body_entered(body):
if body is StaticBody2D:
print("kine:")
if body.name == "StaticBody2D2": #Works with .get_name() ==
print("kine:")
if body.get_node("Area2D2/CollisionShape2D2").get_name() == "CollisionShape2D2":
var collpath = body.get_node("Area2D2/CollisionShape2D2")
climbing = true
print("kine:node: ",collpath)
else:print("kine:3")
else:print("kine:2")
else:print("kine:1")
I think you’re going to need to provide more details about what you’re trying to achieve/what’s not working if you want a clear answer (i.e. are any of the print statements getting hit or is the function just not calling at all).
My first question is why do you have an Area2D as a child of a PhysicsBody? The first collision shape on each body provides collision detection for that body and as such the Area2Ds are not needed for detecting collision between the KinematicBody2D and the StaticBody2D. So, unless the Area2Ds are providing some other functionality, I would remove them and just use the collision shapes of the two physics bodies. Area2D/3Ds are generally used for interaction ranges such as pickups, buttons and automatic doors and such as they detect overlapping rather than collision.
If they’re still not colliding, my only suggestion (without more information) would be to check the collision layers. Collision Layer sets which layer(s) the object is in and Collision Mask sets which layer(s) it will check for collisions in. Basically if your KinematicBody is in layer 1 and your StaticBody is in layer 2, the KinematicBody will only detect a collision with the StaticBody if its mask is set for layer 2.
Hi everyone, I was trying to detect the Area2D2’s CollisionShape2D2 of the StaticBody2D2 by using the Area2D’s CollisionShape2D of the KinematicBody2D because I needed the KinematicBody2D to climb the Area2D2’s CollisionShape2D2 of the StaticBody2D2 (the square collision shape detection) from KinematicBody2D entering to square collision until its exit. By lucky chance, I tried to do it backwards, and now it works. I mean, now the Area2D2’s CollisionShape2D2 of the static body2D2 detects the climb of the KinematicBody2D scene root. Finally, the Area2D and CollisionShape2D of the KinematicBody2D are useless now, because I just needed the Area2D2 and the CollisionShape2D2 of the StaticBody2D to detect the KinematicBody2D.
I did this same silly thing previously, i wanted to detect using character2D’s Area2D with collisionshape towards another character2D with similar structure. It did not go well too. Have you found out a way for Area2D-Area2D detection?