0 votes

I've created a destructible environment system using subdividing, and I've applied that system to some 2D squares, using this code:

func _on_block_area_entered(_area):
if size <= min_size:
    queue_free()
    call_deferred("area_set_shape_disabled")
    return
for i in range (0,2):
    var newNode = duplicate()
    newNode.size = size/2
    get_parent().call_deferred("add_child", newNode)
    newNode.set_scale(get_scale()/2)
    newNode.set_position(Vector2(get_position().x - size/4 + (size/2 * i), get_position().y - size/4))
for i in range (0,2):
    var newNode = duplicate()
    newNode.size = size/2
    get_parent().call_deferred("add_child", newNode)
    newNode.set_scale(get_scale()/2)
    newNode.set_position(Vector2(get_position().x - size/4 + (size/2 * i), get_position().y + size/4))
queue_free()

The blocks have physics, but I'm not really sure how I'm supposed to make the hitboxes subdivide along with the sprites. When I partially destroy a block, the sprite gets chunks taken out of it, but the hitbox stays the exact same as the original block sprite. It's it a bit hard to explain, so here's a GIF of it happening.

Here's the git repository, if that's helpful.

in Engine by (26 points)

Please log in or register to answer this question.

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 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 webmaster@godotengine.org with your username.