How to make the arrow go through the enemy

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By slippe

Hello everyone, I ran into the following problem when creating my game:
I made a flying arrow from a trap, but when it flies out, it does not go through the enemy, but disappears, I would like it to fly through the enemy and kill the main character

func _on_arrow_body_entered(body):
 if "Player" in body.name:
	body.die()
 queue_free()
:bust_in_silhouette: Reply From: ponponyaya

Don’t need to use code, just try to set Collision Layer and Collision Mask, let the arrow can detect Player and ignore enemies.
If you don’t know what is Collision Layer, take a look at this video.

:bust_in_silhouette: Reply From: jgodfrey

It looks like you call queue_free() on the arrow no matter what it has collided with. Maybe you want this?

func _on_arrow_body_entered(body):
    if "Player" in body.name:
        body.die()
        queue_free()

Notice, queue_free() is only called when the collision is with the Player (due to the indention changes).

I already tried to do this, yes, the arrow goes through enemies and only kills the hero, but the arrow also goes through all obstacles

slippe | 2022-02-23 08:47

maybe:

func _on_arrow_body_entered(body):

    if !"EnemyName" in body.name:
    
        body.dont_go_through()   ## or body.die() or body.whatever()

        queue_free()

or, just, add the nodes to groups and have the arrow hit everything unless it’s in the enemies group. lots of ways to solve this…

CassanovaWong | 2022-02-24 04:59

:bust_in_silhouette: Reply From: Malwina Czarnecka

I had the same problem, still don’t know how to solve it