Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PopeRigby |
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.