Skip to content
A script that takes a sprite, divides it into blocks and makes them explode πŸ’₯!
GDScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Updated README, CHANGELOG and added some examples Jul 15, 2019
.gitattributes
.gitignore
CHANGELOG.md Updated README, CHANGELOG and added some examples Jul 15, 2019
LICENSE Initial commit Jul 4, 2019
README.md Updated README Jul 15, 2019
default_env.tres Restructured project Jul 15, 2019
explode_object.gd
icon.png Restructured project Jul 15, 2019
icon.png.import Restructured project Jul 15, 2019
object.tscn Restructured project Jul 15, 2019
particles.tscn Restructured project Jul 15, 2019
particles_material.tres
project.godot Restructured project Jul 15, 2019
test.tscn Updated test scene Jul 15, 2019

README.md

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

Parameters

Blocks Per Side

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.

Blocks Impulse

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

Blocks Gravity Scale

Name Type Description
blocks_gravity_scale float The gravity of the blocks.

Debris max time

Name Type Description
debris_max_time float The seconds it will pass until the blocks become STATIC.

Collision layers

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.

Collision masks

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.

Debug mode

Name Type Description
debug_mode bool Prints some debug data.

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

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.

You can’t perform that action at this time.