Godot Version
4.6.1
Question
I’m trying to get bullets to pierce enemies when they have a piercing debuff, but since I’m using Character body based bullets, it might be a bit tricky. Since I’m calling a damage function through the bullet, I need the bullet to be able to pierce enemies and only damage them once. I tried doing this through an array that stored the id’s of enemies hit so they wouldn’t get hit again, but that lead to the bullets neither damaging nor going through the enemy. The code for that looked like this:
var enemies_hit : Array = []
var collision = move_and_collide(direction * speed * delta)
if collision != null :
if collision.get_collider().has_method("damage"):
if collision.get_collider().pierce != true:
collision.get_collider().damage(dmg, 0)
queue_free()
else:
for i in enemies_hit.size():
if enemies_hit[i] != collision.get_collider_id():
collision.get_collider().damage(dmg, 0)
enemies_hit.push_back(collision.get_collider_id())
If I’m doing this wrong or if this needs to use an area body node please let me know