A script that takes a sprite, divides it into blocks and makes them explode π₯!
Right now, the sprites must be square for this script to work properly.
Each destructible object must follow this structure and must be its own Scene
file.
RigidBody2D
βββ Sprite
βββ CollisionShape2D
βββ RectangleShape2D
- Create a
Node2D
that will contain all the destructibles objects (e.g.destructible_objects
). - Add a
Node2D
as a child node of the priorNode2D
(e.g.object_01
). - Instance the destructible object
Scene
file. - Attach
explode_object.gd
to the destructible object as aScript
.
The reason for organizing it this way is because then you can add particles (Partcicles2D
or CPUParticles2D
) or hitboxes (Area2D
) or whatever you feel like to the Node2D
(e.g. object_01
) holding the main RigidBody2D
and you can then use this script to control those nodes.
Name | Type | Description |
---|---|---|
blocks_per_side |
int |
The blocks per side. Minium 2 . Maximum 10 . |
Example: 4
block per side makes a total of 16
blocks.
Name | Type | Description |
---|---|---|
blocks_impulse |
float |
The "force" of the blocks when they explode. |
Name | Type | Description |
---|---|---|
blocks_gravity_scale |
float |
The gravity of the blocks. |
Name | Type | Description |
---|---|---|
debris_max_time |
float |
The seconds it will pass until the blocks become STATIC or, if remove_debris is set to true , the blocks dissapear. |
Name | Type | Description |
---|---|---|
remove_debris |
bool |
Controls whether the debris stays or disappears. If set to true , the debris will dissapear when debris_max_time is over. |
Name | Type | Description |
---|---|---|
collision_layers |
int |
The collision layers of the blocks. |
Sum all the values of the layers.
Example: Layer 1
value is 1
. Layer 5
value is 16
. So collision_layers
would be 17
.
Name | Type | Description |
---|---|---|
collision_masks |
int |
The collision masks of the blocks. |
Sum all the values of the layers.
Example: Layer 1
value is 1
. Layer 5
value is 16
. So collision_layers
would be 17
.
Name | Type | Description |
---|---|---|
debug_mode |
bool |
Prints some debug data. |
See CHANGELOG.
- Me π hiulit.
Thanks to:
- Airvikar - For this Youtube video that is the code base for this script.
- Securas - For all the great games and Twitch streams that give me lots of ideas, and particularly, the destructible objects one.
- Scott Lembcke - For letting me know about Voronoi regions (which aren't currently available) and helping me with adding more depth to the explosion (random collisions and z-index).