I have a project where warriors are generated and they follow a route. In this route has a tower, when a warrior overlaps that tower, it takes 5 of it life, and he does it every 1 second.
Code of the moment of the collision of the warrior with the tower (Warrior Blueprint): Call Even Lose Life
Look that the moment he overlaps the tower, he starts to move towards it. After that he calls an event that is present in the blueprint of the tower.
Event that was called (Tower Blueprint): Execute Event Lose Life and call Event Attack Tower
This event causes the life of the tower to be shortened by 5. Soon afterwards it is called an event in the warrior that is colliding with the tower.
Event called by the tower (Warrior Blueprint): Execute Event Attack Tower and Call Event Lose Life
This event is only to be given a 1 second interval between each attack by each warrior. At least that was the idea.
I could simply loop in the blueprint of the tower and multiply the damage (5) by the amount of warriors colliding, but it does not seem right to me.
I imagine the problem is because the event in the tower (image 2 of question) is being called multiple times without even being finalized.
In the game, when there is only one warrior overlapping the tower, everything happens correctly:
1 second interval between images.
With more than one warrior overlapping the tower, tower life only decreases with the arrival of a new warrior. While a new warrior does not come to life he remains intact:
When in reality what should happen was each of them take 5 life per second. Then 3 warriors, 15 life per second.
The way I did these 15 lifetimes will not be taken away at the same time, as the warriors have come at different times.
Exemplifying:
- Warrior 1 arrived in the tower at 15.2 seconds.
- Warrior 2 arrived in the tower at 21.5 seconds.
- Warrior 3 arrived in the tower at 32.8 seconds.
Then in the second 33 (moment where the three warriors have already arrived):
- Warrior 1 will take 5 life from the tower at 33.2 seconds.
- Warrior 2 will take 5 life from the tower at 33.5 seconds.
- Warrior 3 will take 5 life from the tower at 33.8 seconds.
How to make the damage to the tower correctly applied, regardless of the amount of warriors?
EDIT 1 (Attempt made based on Stephen's answer)
Warrior Blueprint:
It works perfectly when it is colliding with only one warrior, when it reaches 1 more, life stops to decrease and decreases 5 for each new warrior that overlaps.
EDIT 2 (getting deeper into the tests)
Pretty much the same code as the first edition, with the difference that I added a print at the end of the loop (when it is finalized) and added another condition to take the test:
In the print will appear the actor's name + the word "acabou" + condition value.
In Game:
As soon as the second warrior overlaps the tower, the loop of the first and second warrior ends. This happens with both conditions.
The loop is ending incorrectly and I do not know why. Something is making the condition false.
Message Log:
Answer
Variables that prevent the event from being called more than once. That's the secret.
So when calling the event you impose conditions that (visually) the overlap never closes.
In fact, it will be oscillating.
To solve this, as soon as the warrior overrides the tower, have him try to go towards it (simple move to location/actor) until he dies or the tower is destroyed.
The code is very simple:
You use a loop with conditions (see in the image).
Unfortunately I had to use two variables, instead of using only the life of the tower, because it was giving error.
Basically, because Event Tick of the tower, which destroys her as soon as her life arrives. Then I gave the reference error...
Being straightforward, before the tower is destroyed, it defines this Boolean variable as true, thus closing the loop.
No comments:
Post a Comment