![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Leandro |
Greetings… I’m learning Godot (and trying to shape my brain from structured programming to object oriented programming) by creating a simple Asteroids like game.
So far I added ship movement, shots and a basic enemy (each one in different scenes, and the player ship adds instances of the shots one level above, on the main scene). But I still have no idea of how to deal with collisions. I cannot understand signals, even after the tutorials.
So, what I’m trying to do…
-
Player shots are “Area 2D” and enemy is Rigid Body 2D.
-
I added a “signal hit” after Extends Area 2D (trying to immitate the “Dodge the Creeps” tutorial on the Godot Learning.
-
I added a “body_entered” signal and clicked on “connect” and “connect’” again.
-
In the PlayerShot script, Godot automaticallt added a function “_on_PlayerBasicShot_body_entered(body):” where I made the shot invisible after hitting the collision of the enemy ship. It’s working so far until this point…
But it seems that the signal I did served only for the shot. Suppose that I have more than one instance of the enemy ship, how can I make the program recognize which one of them was hit, and how can I pass the signal to the enemy scene so I make a function to destroy it? Thanks in advance.
P.S.: Why the heck I need to add that “signal hit” in code if the created signal connected automatically to another function Godot created?