0
\$\begingroup\$

I have a project where 1 warrior is generated every 5 seconds. This warrior as it is generated tries to follow a path that contains 4 target points. Between the target point 1 and the target point 2 there is a tower.

Then the warrior is going to meet the target point 2, but as soon as he hits the tower, he fails to reach the target point 2 and goes to meet it until it is destroyed.

enter image description here

The part of the code circled in pink was to be executed only after the destruction of the tower (when the life of the tower reaches 0), which does not happen, but the worst thing is that when it executes, it does not execute completely, the tower is not destroyed, but the warrior moves toward target point 2.

Result in game:

enter image description here

Look that the impression occurs for the two warriors.

Maybe the message log will help:

enter image description here

I decrease the delay time of the loop to 0.1 and as there is no time for the second warrior to overlap the tower along with the first warrior, everything works correctly.

The problem occurs when more than one warrior reaches the tower simultaneously.

\$\endgroup\$
4
\$\begingroup\$

The error message you're getting is that the game is trying to cast to the tower and failing. The Destroy part of your code is also getting run because of the text on screen says so.

You need to make sure that after the tower is not being cast to after it has been destroyed. The easiest way to do this is to set up a new boolean (bTowerIsDestroyed) and set it to false at run time.

When the tower is destroyed, set it to true and put in a branch in before casting to only run if it is still false. If it's true, then you can send your warriors to the next target point.

\$\endgroup\$
0
\$\begingroup\$

The overlap between the warrior and the tower swings when more than one warrior is overlapping the tower.

To solve this, just add a Boolean variable that prevents (in the case of the question) the loop being called more than once.

In order for the reference to the tower not to be lost, the ideal is to add an event with a parameter to store the tower and within it execute the loop.

Something like that:

enter image description here

To help you understand what I did, if any questions remain, I recommend taking a look at the answer to another question I asked:

Way to store object reference?

\$\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.