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.
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:
Look that the impression occurs for the two warriors.
Maybe the message log will help:
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.
Answer
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:
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?
No comments:
Post a Comment