I can't make a coin disappear using body_entered func

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

warning: English isn’t my first language. Bear with me.

Basically, I am doing a little platformer game and I want to make a coin disappear when the player goes to collect it. I am using the body entered function but i must be doing something wrong:

extends Area2D

func _on_Coin_body_entered(body):
	if body.name == "Player":
		queue_free()

What could be the reason? I am using Godot v3.4.2

Thanks in advance!

Do you have several Player nodes in your scene? Check the node names in the Remote scene tree dock while the project is running. You can do so by clicking Remote in the Scene tree dock that appears after starting the project from the editor.

Calinou | 2022-02-27 22:55

:bust_in_silhouette: Reply From: Box_

Try this.

add the player to a group named Player then changed the script to this

func _on_Coin_body_entered(body):
if body.is_in_group(“Player”):
queue_free()

:bust_in_silhouette: Reply From: ponponyaya

I think it’s ok! I am not a English native speaker neither.
Anyway, theye are many reasons may cause your question.

If you got errors, fix those errors first.

If you don’t have any error, you may try debug like this:
1.Check your signal.
Since you are using body_entered function, you have to make sure it does connected.
2.Check your collision.
(1) Make sure your Coin can detecte your Player. I mean they should have right collision layer and collision mask. And more basically make sure both of the collision shape are fine.
(2) To find the collider, you can use print statement to test it, or use Breakpoints to find it. If you don’t know how to do that, take a look at this video.

Hope it works.