Idea is, there are 3 scenes - player, a coin, and a main scene. At the ready() of the main scene (just a sprite with a camera) I create one instance of a player scene and one instance of a coin scene at random locations. Player emit "hit" signal when it touches the coin, which is connected to the main scene with a collable "jump", that should move the coin to a random location. An it works, but only once. Coin jumps, but touching it again does nothing. Only touching the spot where it WAS at the start. It looks like the contact area just stays where the coin spawned. Coin has no script, it is just a sprite with a rigid body and an area, and player has an "enter rigid body" signal to react to it. What am I doing wrong?`
extends Sprite2D
var xpos = 0
var ypos = 0
var coin
var rnd = RandomNumberGenerator.new()
var player
var scene
Called when the node enters the scene tree for the first time.
func _ready():
rnd.randomize()
xpos = rnd.randf()170
ypos = rnd.randf()110
scene = load("res://player.tscn")
player = scene.instantiate()
player.position = Vector2(xpos-85,ypos-55)
add_child(player)
xpos = rnd.randf()170
ypos = rnd.randf()110
scene = load("res://coin.tscn")
coin = scene.instantiate()
coin.position = Vector2(xpos-85,ypos-55)
add_child(coin)
player.connect("hit", _jump)
func _jump():
xpos = rnd.randf()170
ypos = rnd.randf()110
coin.position = Vector2(xpos-85,ypos-55)
Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass`