![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | keidav |
I am trying to erase a tile when a collision happens, the following is part of a projectile class that is a CharacterBody2D. I want to erase a tile when it collides with a tile in Tilesets/Breakable.
My detection code works, but I am not mapping something correctly with the collided tile to erase it.
var breakable_map
var collision
var collided = false
func _ready():
breakable_map = get_parent().get_node("Tilesets/Breakable")
pass
func _physics_process(delta):
if !collided:
calc_velocity.x = SPEED * delta * direction
translate(calc_velocity)
collision = move_and_collide(calc_velocity )
$AnimatedSprite2D.play("shooting")
if collision != null and !collided:
collided = true
var body = collision.get_collider()
if body.is_in_group("enemies"):
body.hit(HIT_POINTS)
elif body.name == "Breakable":
var tile = breakable_map.local_to_map(breakable_map.to_local(to_global(position)))
breakable_map.erase_cell(0, tile)