![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Ombre |
Hi, I’m making an Asteroids clone with Godot. The MainScene generates a number of asteroids, making new ones appear when another one gets out of screen, and the Player script generates bullet when the shoot key is pressed. I’ve been trying to use signals to connect the _on_body_entered on the Bullet script, but the only workable function I found uses get_child(0) which doesn’t return the right instance. I also don’t really know where to emit the signal from!
So far I have :
if Input.is_action_just_pressed("shoot"):
b = Bullet.instance()
owner.add_child(b)
b.add_to_group("Bullets")
b.transform = $Muzzle.global_transform
get_parent().get_child(0).emit()
and on the Bullet scene :
func emit():
emit_signal("bullet_collision")
print("emission")
func _on_Bullet_body_entered(body):
if body.is_in_group("Asteroids"):
print("bullet collision")
body.queue_free()
queue_free()
and in the ready of Bullet :
connect("bullet_collision", self, "_on_Bullet_body_entered")
Oh and the collisions work fine when they’re not instances. Thanks!