Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DrewS |
How would I go about creating a Coin? Say killing an enemy causes coins to rain down, and the player upon running over them would get some value. I started by designing a RigidBody2D that is the coin, have it collide with the player layer and the obstacles layer. However, the coin collides with the player when it should trigger on the player. I want to free the coin when it collides specifically with the player and inform the player that something happened.
I was thinking that signals could do this, but the player would have to connect to many, possibly hundreds of coin’s signals when they are created. I am not sure how to go about this. This is what I have:
extends RigidBody2D
export (String) var type = "coin"
export (int) var value = 4
signal item_pickup
func _ready():
pass
func _on_Coin_body_entered(body):
emit_signal("item_pickup", type, value)
queue_free()
Now I know this is wrong, as it cannot call _on_Coin_body_entered
on itself, but, as I stated the emit_signal
for the player will be a problem as well. I could not find any solutions from the searches I tried.