Godot Version
`4.5 stable
Question
hello there! im working on my small top-down 2d game about tanks
so here is my problem:
i want to implement wall breaking feature. my walls are placed as tilemaplayer. to make visible, that u can actually break this wall, I decided to do this with the flash effect when hitting a wall, but I came across the fact that all the tiles of the wall are highlighted, and I need to implement it so that only the tile that is hit is highlighted.
here are my scripts:
##projectile.gd
extends Area2D
@export var speed: float = 600
@export var damage: float = 1
@export var lifeTime: float = 2.00
func explode():
queue_free()
#speed = 0
#$Sprite.hide()
#$Explosion.show()
#$Explosion.play()
func _on_body_entered(body: Node2D) -> void:
$SFXHit.play()
explode()
if body.has_method("take_damage"):
if body is TileMapLayer:
body.take_damage(damage, body.local_to_map(global_position))#emit_signal("get_cell_vector", body.local_to_map(global_position))
else:
body.take_damage(damage)
func _on_life_timer_timeout() -> void:
explode()
func _ready() -> void:
$LifeTimer.wait_time = lifeTime
$LifeTimer.start()
func _process(delta: float) -> void:
position += transform.x * speed * delta
func _on_explosion_animation_finished() -> void:
pass
#queue_free() # Replace with function body.
##tilemaplayer.gd
extends TileMapLayer
@onready var flash_shader = load("res://shaders/hitFlashEffect.gdshader")
var cell : TileData
func take_damage(amount, cell_vector : Vector2):
cell = get_cell_tile_data(cell_vector)
cell.set_custom_data("health", get_cell_tile_data(cell_vector).get_custom_data("health") - amount)
flash(cell)
func flash(cell : TileData):
$FlashTimer.start()
var flash_material = ShaderMaterial.new()
flash_material.shader = flash_shader.duplicate()
cell.material = flash_material
cell.material.set_shader_parameter("flash_modifier", 0.5)
func _on_flash_timer_timeout() -> void:
cell.material.set_shader_parameter("flash_modifier", 0.0)
##hitFlashEffect.gdshader
shader_type canvas_item;
uniform vec4 flash_color: source_color = vec4(1.0);
uniform float flash_modifier: hint_range(0.0, 1.0, 0.1) = 0;
void fragment() {
vec4 color = texture(TEXTURE, UV);
color.rgb = mix(color.rgb, flash_color.rgb, flash_modifier);
COLOR = color;
}
link to demonstration 2025-09-16 23-30-17
many thanks!!!