How to make coin colectibles in godot 4.4

I’ve tried many codes to do a coin pickup but everytime i touch the coins colision box it just doesnt work

extends Area2D

func _on_body_entered(body: Node2D) -> void:
	if body.name== "Player":
		self.queue_free()

this is the last code i tried

  1. Have you checked that _on_body_entered is connected to the signal?
  2. Using the name is quite an unsafe way to check for a node. I would suggest using groups.
2 Likes

Using the groups fixed the problem thx for your help :smiley:

Im also struggling with this can you provide the fix please.

Put the player in some group, e.g. “Player”

Script:

extends Area2D

const player_group: String = "Player" # replace with group name

func _on_body_entered(body: Node2D) -> void:
	if body.is_in_group(player_group):
		queue_free()

Connect the signal “body_entered” to _on_body_entered