Godot Version
4.2.1
Question
I’m new to Godot. I’m trying to build a basic ARPG. I have character movement, a basic enemy that is a character2D, and the ability to create a circle at a point chosen by mouse click.
The spell is an Area2D. I’ve managed to get the spell’s stats to grab the player’s stats and modify them. The point of confusion has to do with how the enemy takes damage from the spell. I was working under the assumption that I’d use signals to accomplish this. I was getting confused about which object is emitting the signal and which is catching it to do something with and then the specifics of how to do that. I don’t seem to be able to directly use the signal UI in the editor to connect the objects since it seems to only work for children/parents. An explanation of how this should work would be appreciated. Also, it doesn’t seem like the signal carries any other data? So I’m confused about how to pass the spell’s damage to the enemy since neither the enemy nor the spell by default exists in the scene hierarchy until created. Plus there might be multiple spells and multiple enemies to pass and receive info at any given time.
However, when I was looking again at Area2D, I saw functions that get overlapping areas and bodies. This seems like it might work for my purpose since I would just get the reference to things that the spell hit. However, I’m still not sure if the enemy would use this or the spell would use this. Additionally, the documentation says something about the collisions being processed at the same time and to consider using signals, but I don’t really understand why you might want to use this or signals over the other. Which is more appropriate to use and why?
Code:
Spell:
Player:
World/Gameplay:
Enemy: