I’m creating a tower defense game with blueprints. I made a turret and when there’s several enemies in front,it attacks at the middle. It can’t lock to a single target when there’s multiple targets in front. How can I solve this problem? I want the turret to lock on a target until it’s dead. My BP setup for rotation:
I’m making a TD game as well. Here’s what I did (or a simplified version of it).
-
Add a variable to your Tower BP called TargetEnemy.
-
From the On See Pawn event, check if TargetEnemy is invalid. If it’s invalid, then set TargetEnemy to the Pawn. That’s it.
-
The rest of your graph would then use TargetEnemy instead of Pawn, but it would be called only when the tower fires. Either in tick or in a delay.
In my game, I also had to check for line of sight in #3. If you lose sight, you can set TargetEnemy to None, or you can wait a bit to see if you regain line of sight and if not, only then you set it to None.
If the Enemy is Destroyed, it’ll be cleared automatically, but if you have death animation, you’ll have to clear TargetEnemy yourself. I have an event dispatcher in the enemy that the tower binds to for this. Or you can just add a IsDead event to your enemy and check it in #2. If it’s dead, remove and/or replace the variable.
Thanks.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.