All Projects β†’ hiulit β†’ Godot 3 2d Destructible Objects

hiulit / Godot 3 2d Destructible Objects

Licence: mit
A script that takes a sprite, divides it into blocks and makes them explode πŸ’₯!

Projects that are alternatives of or similar to Godot 3 2d Destructible Objects

Godot Platformer 2d
2d Metroidvania-inspired game for the 2019 GDquest Godot Kickstarter course project.
Stars: ✭ 365 (+96.24%)
Mutual labels:  godot-engine, 2d
Creature godot
2D Skeletal Animation Creature Runtime for Godot Engine
Stars: ✭ 70 (-62.37%)
Mutual labels:  godot-engine, 2d
Godot 3 2d Crt Shader
A 2D shader for Godot 3 simulating a CRT
Stars: ✭ 183 (-1.61%)
Mutual labels:  godot-engine, 2d
Fxgl
Stars: ✭ 2,378 (+1178.49%)
Mutual labels:  2d
Skija
Java bindings for Skia
Stars: ✭ 2,292 (+1132.26%)
Mutual labels:  2d
Black
World's fastest HTML5 2D game engineΒ Β Β πŸ›Έ
Stars: ✭ 174 (-6.45%)
Mutual labels:  2d
Godot Beginner 2d Platformer
Learn to create a 2d platform game with the Godot game engine. This is a beginner programming tutorial.
Stars: ✭ 183 (-1.61%)
Mutual labels:  godot-engine
Wechart
Create all the [ch]arts by cax or three.js - Cax ε’Œ three.js εˆ›ι€ δΈ€εˆ‡ε›Ύ[葨]
Stars: ✭ 152 (-18.28%)
Mutual labels:  2d
Unity Aseprite Importer
An aseprite-file importer for unity written in C#, built upon the experimental AssetImporter API
Stars: ✭ 177 (-4.84%)
Mutual labels:  2d
Nakama Godot Demo
A demo project with Godot engine and Nakama server.
Stars: ✭ 171 (-8.06%)
Mutual labels:  godot-engine
Godot Ci
Docker image to export Godot Engine games. Templates for Gitlab CI and GitHub Actions to deploy to GitLab Pages/GitHub Pages/Itch.io.
Stars: ✭ 168 (-9.68%)
Mutual labels:  godot-engine
Godot card engine
A plugin for Godot to create card based games
Stars: ✭ 160 (-13.98%)
Mutual labels:  godot-engine
Creature ue4
Unreal Engine 4 Runtimes for Creature, the 2D Skeletal + Mesh Animation Tool
Stars: ✭ 174 (-6.45%)
Mutual labels:  2d
Tosios
The Open-Source IO Shooter is an open-source multiplayer game in the browser
Stars: ✭ 157 (-15.59%)
Mutual labels:  2d
3d Bat
3D Bounding Box Annotation Tool (3D-BAT) Point cloud and Image Labeling
Stars: ✭ 179 (-3.76%)
Mutual labels:  2d
Physac
2D physics header-only library for videogames developed in C using raylib library.
Stars: ✭ 151 (-18.82%)
Mutual labels:  2d
Opensuspect
OpenSuspect is an open source social deduction game, similar to Mafia or Among Us.
Stars: ✭ 176 (-5.38%)
Mutual labels:  godot-engine
Unitymathreference
Math reference for games and more. All visualized in Unity3D.
Stars: ✭ 166 (-10.75%)
Mutual labels:  2d
Rgx
Modern mid-level 2D graphics library
Stars: ✭ 172 (-7.53%)
Mutual labels:  2d
Vrworkout
High-intensity virtual reality workout game
Stars: ✭ 166 (-10.75%)
Mutual labels:  godot-engine

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].