I added a projectile object to the ShootAction

This works really well for player turns. When a projectile is fired, it gets its orientation from the target world position and the shooter world position.
However, this feature often does not work properly when it is the enemy AI’s turn.

The debug log in the 4th photo shows that the vector calculated through the two world positions has a magnitude of zero. Also, after the player unit is killed, I can see the debug log as like in the 5th image. From all of this, I can infer that the value of the shooter position is not updated during the enemy AI’s turn. How can I fix this?

As it turns out, it was a simple matter. I thought the UnitActionSystem script was managing the enemy AI units, but after re-reading the script, I realized that the EnemyAI script was managing them, declaring the Selected Enemy Unit as a variable and returning a value, and adding a conditional statement based on the player’s turn in the function that instantiates the projectile. To do this, I modified the EnemyAI script with a singleton pattern.

Well done getting that solved

For future code pastes, please paste in the text of the script using our formatting system (type three backwards apostrophes on their own line (this is the ` next to the 1 key, not the ’ by the return key) like this

Your code
It will then look like

Your code

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms