This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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()
in Engine by (15 points)

3 Answers

0 votes
Best answer

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.

by (526 points)
selected by
0 votes

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).

by (22,704 points)

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

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...

0 votes

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

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.