• Stars
    star
    393
  • Rank 109,518 (Top 3 %)
  • Language GDScript
  • License
    MIT License
  • Created over 5 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

More Repositories

1

Godot-3-2D-Day-Night-Cycle

A 2D ☀️ Day / 🌔 Night cycle using CanvasModulate and a moon light effect using Light2D.
GDScript
329
star
2

Godot-3-2D-CRT-Shader

A 2D shader for Godot 3 simulating a CRT
GLSL
299
star
3

Unofficial-Godot-Engine-Raspberry-Pi

Unofficial Godot Engine binaries for the Raspberry Pi.
281
star
4

Sassy-Gridlover

Super easy to use Sass mixins to establish a typographic system with modular scale and vertical rhythm. Based on the Gridlover app.
HTML
221
star
5

RetroPie-Godot-Engine-Emulator

A scriptmodule to install a Godot "emulator" for RetroPie.
Shell
91
star
6

Delaunator-GDScript

A GDScript port of Delaunator: A fast library for Delaunay triangulation of 2D points.
GDScript
80
star
7

GDScriptify

A magical documentation tool for GDScript.
JavaScript
48
star
8

Godot-Plugin-Particles-Renderer

A Godot plugin to render particles into a sprite sheet
GDScript
40
star
9

itchio-godot-scraper

A scraper for Godot games hosted on https://itch.io.
JavaScript
28
star
10

cross-compile-godot-raspberry-pi

A script to easily cross-compile Godot binaries for the Raspberry Pi from Linux x86_64 and an extra script to easily transfer the compiled Godot binaries to the Raspberry Pi using rsync
Shell
28
star
11

aseprite-to-godot-variables

A Lua script to create arrays of colors and indexes of those colors from an Aseprite sprite to be used in Godot.
Lua
23
star
12

Lospec-Palette-List

Browse through thousands of awesome Lospec palettes
GDScript
22
star
13

Murtop-Raspberry-Pi-Bartop-Arcade-Machine-Project

Personal project to create an actual playable Bartop Arcade Machine from scratch using a Raspberry Pi with RetroPie and lots of wood, paint and wires :)
20
star
14

Godot-3-2D-Fake-Explosion-Particles

A script to simulate exploding particles.
GDScript
18
star
15

Godot-3-2D-Fake-Snow-Particles

A script to simulate snow particles ❄️
GDScript
18
star
16

Godot-3-2D-Fake-Confetti-Particles

A script to simulate confetti particles 🎉
GDScript
14
star
17

RetroPie-Itchio-Godot-Scraper

A tool for RetroPie to scrape Godot games hosted on https://itch.io.
Shell
12
star
18

RetroPie-Convert-Videos

A tool for RetroPie to convert videos.
Shell
12
star
19

ppa

A PPA repository for my packages (Godot)
Shell
8
star
20

Godot-3-2D-Draw-Sprite

A script to create "sprites" using the _draw() function to easily create patterns, change the color palette, or change the pixel size.
GDScript
8
star
21

es-pixel-theme-extras

Script for RetroPie to install some extras for the EmulationStation's Pixel theme (Retropie menu icons, boot splashscreen and launching images)
Shell
5
star
22

RetroPie-Shell-Script-Boilerplate

A template for building shell scripts for RetroPie.
Shell
4
star
23

RetroPie-Fun-Facts-Splashscreens

A tool for RetroPie to generate splashscreens with random video game related Fun Facts!.
Shell
4
star
24

Godot-2D-Platformer-Test

GDScript
2
star
25

RetroPie-Limit-Last-Played-Games

A tool for RetroPie to limit the number of 'last played' games.
Shell
2
star
26

es-theme-extras

Script for RetroPie to install some extras for EmulationStation themes (icons, splashscreens and launching images)
Shell
1
star
27

Stylus-Mixins

A set of Stylus mixins
CSS
1
star
28

barcelona-bicycle-anchor-points

Find public bicycle anchor points near you in Barcelona!
JavaScript
1
star
29

RetroPie-Extras

A collection of my own scripts for RetroPie
1
star
30

lospec-api

An API for the Lospec Palette List
JavaScript
1
star
31

RetroPie-Murtop

A script to install Murtop on Retropie
Shell
1
star