Godot Version
4.2.1
Question
I am making a spell that hits enemies in it’s area. I would like to make one version that does this once and one that does this damage over time at a certain interval. The one that does it once is easy enough. However, I’m not sure what the best solution is for the one that does it multiple times. I’ve gotten 3 different methods working, but each seems a bit hacky and I’m not sure if there is a better way. Unfortunately I don’t have version management going at the moment since I’ve just been playing around, so I don’t have the exact code, but I just want to get an idea of how these different functions work.
Option 1: I called the damage function in physics process and had some if statement to only allow it in after certain intervals.
Option 2: I use the on_body_entered signal to call a damage function that enters a while loop and used a timer to only allow it through an if statement when the timer was zero.
Option 3: The latest attempt was to use a timer signal to trigger the damage function whenever the timer ran out for the interval I wanted. The problem with this is that it obviously doesn’t do anything right when the spell happens, which is what I want. I tried just calling the damage function once in _ready(), but that results in get_overlapping_bodies() not returning any bodies. The hacky solution was just to initially start the interval timer at a short time (.02), and then set it to the right time when the timeout function is called. This seems a bit wrong. I’m basically using a magic number to delay it then I’m calling the timer.start() function each time rather than just letting it loop by default.
Could anyone give me a good explanation of what the best way of approaching? Also, I could use an explanation of the timing of the ready function and how/where I should call code that needs to make sure everything is in place first. (I thought that was what ready was for, but I guess not?)