Not sure why, but my 2D ridged body won't be destroyed. Is it because it is an animated sprite? I have attached my script below. Let me know if I have done something wrong?

extends RigidBody2D

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    var bodies = get_colliding_bodies()

    for body in bodies:
            if body.is_in_group("Bricks"):
            body.queue_free() 

You just need to indent this line: “body.queue_free()” one tab (or however many spaces you’re indenting) I’d also check that the other rigidbodies are in group “Bricks” as well.

If the animated sprite is still showing I’d check to see if it is a child of the Rigidbody (the one colliding with the object that has the above script). If it’s not I’d go up enough nodes until you have the entire node structure of the brick destroyed.

An example:

AnimatedSprite | |—RigidyBody2D ——|—Collision shape / Collision Polygon

You’d need to call body.get_parent().queue_free() to remove the brick, because the brick’s root node isn’t the RigidBody2D, but rather it’s parent (the animated sprite). I hope that makes sense and helps!

technically you aren't saying that it is in a group, so if the node that the script is on isnt in a group, it won't be deleted. if you want the node to which that script is attached to free, then you just say 'queue_free()' not body.queue_free() since body is just the iterator variable and is never explicitly the same as the script's node (according to what youve shown)

5 years later