0
\$\begingroup\$

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

enter image description here

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

enter image description here

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

enter image description here

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:

enter image description here

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:

enter image description here

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:

enter image description here

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:

enter image description here

In the print will appear the actor's name + the word "acabou" + condition value.

In Game:

enter image description here

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:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Whats “ atacar torre “ ? wWhat exact event is that ? Whats perder vilda ? \$\endgroup\$ – ColdSteel Jun 6 at 15:44
  • 1
    \$\begingroup\$ Sorry ColdSteel. I am not English speaker, so when I "program" I name the events in my language. Atacar Torre => Attack Tower and Perder Vida => Lose Life \$\endgroup\$ – Boneco Sinforoso Jun 6 at 21:00
  • \$\begingroup\$ I dont get the problem, can you explain what do you expect to happen and what is happening? \$\endgroup\$ – ColdSteel Jun 6 at 21:12
  • \$\begingroup\$ From your desired behavior explanation I can only say that: you have 2 events for overlaps: BeginOverlap and EndOverlap (dont recall the exact names, but thats how it works) - now BeginOverlap will only be called once the Actor/Character starts to overlap please note ONCE :) \$\endgroup\$ – ColdSteel Jun 6 at 21:13
  • 1
    \$\begingroup\$ Minion will have states e.g. walking/idle/attacking will have its target (tower in your case, but better to make it as an interface and let tower to derive from targetable/attackable/damageble interfaces. In minion’s tick or BehaviorBP you will query the state if the state is attacking you will execute the attacking logic in this case make the turret 5 hp less. \$\endgroup\$ – ColdSteel Jun 6 at 21:43
1
\$\begingroup\$

The overlap event is working correctly. Your tower doesn't know how many warriors are attacking it, just that something is inside the detection area.

You could try moving the -5 logic to after the branch of your loop where you check for a warrior but I'm not certain if that would work.

The easiest way would be to put the damage inside the warrior blueprint, casting to the tower so they each (after checking the tower still exists so you don't get nullptr errors) do damage rather than having the tower do all the work. This way, it doesn't matter if you've got 1 warrior or 1000 attacking.

\$\endgroup\$
  • \$\begingroup\$ Could this verification of the tower's existence be made in what form? Could I use "is valid?" Is there a function that asks if the actor still exists? I did not want to do a check based on the value of tower life. \$\endgroup\$ – Boneco Sinforoso Jun 7 at 22:18
  • \$\begingroup\$ I decided to use the function Is Overlapping Actor. \$\endgroup\$ – Boneco Sinforoso Jun 7 at 22:25
0
\$\begingroup\$

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:

enter image description here

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.