How to make Breakable Tiles from a Player Attack in Godot 4
HTML-код
- Опубликовано: 22 июл 2024
- CODE:
extends Area2D
var tilePos = Vector2i(0,0)
func _ready():
tilePos = Global.tileSet.local_to_map(global_position)
func on_area_entered(area):
if area.is_in_group("PlayerHitbox"):
Global.tileSet.erase_cell(0,tilePos)
$Part.emitting = true
await get_tree().create_timer($Part.lifetime,false).timeout
queue_free()
Basic Steps:
1. Create your tileset and player attack (use other tutorials for these)
2. Create a new Area2D scene with a Collision Shape 2D bit bigger than your tiles.
3. Add the code
4. Save the Area2D scene and add it as a scene in a scenes collection tileset*
5. Paint that scene on anything you want to be breakable
*Go to TileSet at the bottom of the screen when selecting your TileMap, click the + button in the bottom left and select Scenes Collection, and then click the other + on the right to add your Area2D scene
TIMESTAMPS
0:00 Intro
0:18 Explanation
0:55 Scene layout
1:17 Code
2:07 Adding scene to tilemap
2:53 Demonstration
Woah this prototype seems very Interesting I'm I hope you'll perhaps show more of it
I didn't need this but I watched the whole thing because that is a really cool idea/implementation...additionally I appreciate you putting the code in the description.
Thank you!