AI Determining Target

Hi people, Hope you’re doing great.
I have an AI character in my Game and has it Pawn Sensing Component on it. The AI character moves to a bunch of other Characters in the game but when my AI character senses the group of enemy it doesn’t justs moves to the closet enemy but confuses and switches it’s target selection rapidly and ends up going to the 3rd or 4th enemy standing in the group leaving the closest enemy behind. How can I make it reach the closet enemy first and then go to 2nd closest enemy and so on?
Example: In Clash of Clans and other RTS games, the enemies first encounter the closest enemy and then move on.
Thank you so much. Hope you understand the question.

I reccomend that you make the AI choose the closest target and move to it, when it gets there Then you choose a new target.

What I think is happening right now is that you are running it on Tick and its constatnly changeing targets because of it. Im not an AI master so I might be wrong.
Hope it solves your problem.

Yes, Pawn Sensing ticks frequently, I have set it to 0.2 Seconds.

Are you choosing a new target to go to every frame?
I know I guy who had the same problem.
And the fix was making the AI go to the target before finding a new one.

Yes, once you have a target, you need to remain on that target until/unless something else causes a change, so stop hunting for a target if you already have one.

Ok Got it, Let me think of some logic,
Thanks

There are a bunch of ways to solve this. For example, you could implement a target selection cooldown that, when a target is selected, you set the timer, which flips a bCanChooseTarget bool back on. You could override this in certain conditions such as taking damage, the target dying or leaving a certain radius. More simply, you could just flip the same bool as soon as a target is chosen and make sure you have a decorator on your BT target selection task that checks the above bool. Ultimately, getting this right is a pretty tricky job that’ll take you a while to get feeling right.

1 Like

Hey, @elguapador I got that, working on this…

Cool. Don’t forget to mark your solution when you find it :slight_smile:

1 Like

Done