A script that takes a sprite, divides it into blocks and makes them explode 💥!

Godot 3 2D Destructible Objects

A script that takes a sprite, divides it into blocks and makes them explode 💥 !

Godot-3-2D-Destructible-Objects

Limitations

Right now, the sprites must be squares or rectangles for this script to work properly.

Prerequisites

Each destructible object must follow this structure and must be its own Scene file.

RigidBody2D
├── Sprite
└── CollisionShape2D
    └── RectangleShape2D

Usage

  • Create a Node2D that will contain all the destructibles objects (e.g. destructible_objects).
  • Add a Node2D as a child node of the prior Node2D (e.g. destructible_object_01).
  • Instance the destructible_object scene file.
  • Attach explode_object.gd to the destructible object as a Script.

Godot-3-2D-Destructible-Objects-Tree

The reason for organizing it this way is because then you can add particles (Partcicles2D or CPUParticles2D), fake particles (like the ones provided with this project), hitboxes (Area2D) or whatever you feel like to the Node2D (e.g. destructible_object_01) holding the main RigidBody2D and you can then use this script to control those nodes.

Of course, you can recreate that tree in GDSscript, with something like this:

var node = Node2D.new()
node.name = "destructible_container"
get_parent().add_child(node, true)

var rigid_body = RigidBody2D.new()
rigid_body.name = "destructible_object"

var sprite = Sprite.new()
# Set the sprite's texture, size, etc.
sprite.texture = preload("res://path/to/texture.png")
...

var collision = CollisionShape2D.new()
collision.shape = RectangleShape2D.new()
collision.shape.extents = Vector2(..., ...)

rigid_body.add_child(sprite, true)
rigid_body.add_child(collision, true)

var script = preload("res://path/to/explode_object.gd")
rigid_body.set_script(script)

# Here you can set the 'rigid_body' variables from the script.
rigid_body.blocks_per_side = ...
rigid_body.blocks_impulse = ...

node.add_child(rigid_body, true)

Parameters

Godot-3-2D-Destructible-Objects-Parameters

Blocks Per Side

Name Type Description Default
blocks_per_side int The blocks per side. Minium 2. Maximum 10 (for performance reasons). 6

Example: 4 block per side makes a total of 16 blocks.

Blocks Impulse

Name Type Description Default
blocks_impulse float The force of the blocks when they explode. 600

Blocks Gravity Scale

Name Type Description Default
blocks_gravity_scale float The gravity of the blocks. 10

Debris max time

Name Type Description Default
debris_max_time float The seconds it will pass until the blocks become STATIC or, if remove_debris is set to true, they dissapear. 5

Remove debris

Name Type Description Default
remove_debris bool Controls whether the debris stays or disappears. If set to true, the debris will dissapear when debris_max_time is over. false 

Collision layers

Name Type Description Default
collision_layers int The collision layers of the blocks. 1

Sum all the values of the layers.

Example: Layer 1 value is 1. Layer 5 value is 16. So collision_layers would be 17.

Collision masks

Name Type Description Default
collision_masks int The collision masks of the blocks. 1

Sum all the values of the layers.

Example: Layer 1 value is 1. Layer 5 value is 16. So collision_layers would be 17.

Collision one way

Name Type Description Default
collision_one_way bool Set one_way_collision for the blocks. false

Explosion delay

Name Type Description Default
explosion_delay bool Adds a delay of before setting object.detonate to false. false

Sometimes object.detonate is set to false so quickly that the explosion never happens. If this happens, try setting explosion_delay to true.

Fake explosions group

Name Type Description Default
fake_explosions_group String Renames the group's name of the fake explosion particles. fake_explosion_particles

This project provides an extra script for creating fake explosion particles. That script uses a group name to be able to find the fake explosion particles more easily.

Randomize seed

Name Type Description Default
randomize_seed bool Randomize the seed. false

Debug mode

Name Type Description Default
debug_mode bool Prints some debug data. false

Changelog

See CHANGELOG.

Authors

Credits

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).

License

MIT License.

Similar Resources

A simple tool who pulls data from Online.net API and parse them to a Prometheus format

Dedibox backup monitoring A simple tool who reads API from Online.net and parse them into a Prometheus-compatible format. Conceived to be lightweight,

Aug 16, 2022

Fleex allows you to create multiple VPS on cloud providers and use them to distribute your workload.

Fleex allows you to create multiple VPS on cloud providers and use them to distribute your workload.

Fleex allows you to create multiple VPS on cloud providers and use them to distribute your workload. Run tools like masscan, puredns, ffuf, httpx or a

Dec 31, 2022

Watches for zips and unzips them

unziploc Watches for zips/tars/rars and unzips them Options: PATHS = /data #Comma seperated list of paths to watch WRITE_DELAY = 1m #How long to wait

Nov 28, 2021

A handy utility to generate configmap and values.yaml of your application for helmifying them

Helmfig Are you tired of writing values.yaml for configmap of your project when you are helmifying them? Helmfig is a handy tool that can generate the

Dec 14, 2022

A long-running Go program that watches a Youtube playlist for new videos, and downloads them using yt-dlp or other preferred tool.

ytdlwatch A long-running Go program that watches a Youtube playlist for new videos, and downloads them using yt-dlp or other preferred tool. Ideal for

Jul 25, 2022

The DGL Operator makes it easy to run Deep Graph Library (DGL) graph neural network training on Kubernetes

DGL Operator The DGL Operator makes it easy to run Deep Graph Library (DGL) graph neural network distributed or non-distributed training on Kubernetes

Dec 19, 2022

Kusk makes your OpenAPI definition the source of truth for API resources in your cluster

Kusk makes your OpenAPI definition the source of truth for API resources in your cluster

Kusk - use OpenAPI to configure Kubernetes What is Kusk? Developers deploying their REST APIs in Kubernetes shouldn't have to worry about managing res

Dec 16, 2022

moreHandlers is a library which makes possible the use of multiple handlers for the MCBE server software

moreHandlers moreHandlers is a library which makes possible the use of multiple handlers for the MCBE server software https://github.com/df-mc/dragonf

Aug 4, 2022

A proof-of-concept project that makes accessible buildkitd daemon from macOS

buildkit-machine buildkit-machine allows you to make buildkitd daemon accessible in your macOS environment. To do so, it uses lima, which is a Linux s

Dec 21, 2022
Comments
  • Implementation of collapse

    Implementation of collapse

    Hi, I working on c++ implementation of your great Destructible (https://github.com/ppiecuch/godot/blob/master/modules/gdextensions/scene/destructible_sprite.cpp) and would like to also implement collapse functionality. I see that it has been started in new_destruction branch but I have a feeling that it is still work in progress. But maybe you could share idea how do you plan to implement this?

    Regards Pawel

  • Fake Particles visiblity

    Fake Particles visiblity

    Pretty easy one, but probably worth mentioning that fake particles can be visible and distracting pre explosion as shown in this simple low bit pixel game I'm working on.

    image

    The yellow there is the bunched up fake particles I assume.

    Easy fix is to set visible = false in _ready, and visible = true before _particles_explode(delta), unless I'm missing some further nuance.

GoBinClassify - A library that makes it easy to classify into groups

GoBinClassify GoBinClassify is a library that makes it easy to classify into gro

Feb 12, 2022
Sapfun - Utility that takes control over your video card coolers to keep it cool and steady

What? sapfun - Utility that takes control over your video card coolers to keep i

Feb 18, 2022
Opinionated platform that runs on Kubernetes, that takes you from App to URL in one step.
Opinionated platform that runs on Kubernetes, that takes you from App to URL in one step.

Epinio Opinionated platform that runs on Kubernetes, that takes you from App to URL in one step. Contents Epinio Contents What problem does Epinio sol

Nov 13, 2022
MongoBackup - This is container that takes backup of MongoDB

MongoBackup This is container that takes backup of MongoDB. It is ment to be ran

Feb 15, 2022
In this repository, the development of the gardener extension, which deploys the flux controllers automatically to shoot clusters, takes place.

Gardener Extension for Flux Project Gardener implements the automated management and operation of Kubernetes clusters as a service. Its main principle

Dec 3, 2022
Hexagonal architecture paradigms, such as dividing adapters into primary (driver) and secondary (driven)Hexagonal architecture paradigms, such as dividing adapters into primary (driver) and secondary (driven)

authorizer Architecture In this project, I tried to apply hexagonal architecture paradigms, such as dividing adapters into primary (driver) and second

Dec 7, 2021
An app that fetches a random name and joke, and combines them.
An app that fetches a random name and joke, and combines them.

Wildfire Backend Assessment An app that fetches a random name and joke, and combines them.

Jan 29, 2022
The OCI Service Operator for Kubernetes (OSOK) makes it easy to connect and manage OCI services from a cloud native application running in a Kubernetes environment.

OCI Service Operator for Kubernetes Introduction The OCI Service Operator for Kubernetes (OSOK) makes it easy to create, manage, and connect to Oracle

Sep 27, 2022
Learning about containers and how they work by creating them the hard way
Learning about containers and how they work by creating them the hard way

Containers the hard way: Gocker: A mini Docker written in Go It is a set of Linux's operating system primitives that provide the illusion of a contain

Jan 7, 2023
ginko-volkswagen detects when your tests are being run in a CI server, and reports them as passing

detects when your ginkgo-based tests are being run in a CI server, and reports them as passing

Dec 4, 2021