Friendly AI's?

I want to make an AI that will protect the player by defeating other enemies. Is there a command like “target nearest AI”? Maybe an array has AI controller, but how would I find the nearest one and target that one only?

Please help

you can use a ‘find all objects of class’ node - set it to your enemy type.

then loop through them all - stashing the distance to the first one. work it out by getting the position of your friendly AI and the position of the enemy AI. subtract one from the other (this gives you a line joining the two). Then use the vector length function. that’s the distance.

every subsequent time you loop, check to see if the distance to the current enemy being checked is less that what is stored. if it is, update the stored distance and store a reference to that enemy. Once the loop is completed you will have the nearest enemy.

You may want to create an object variable in your friendly Ai blackboard to store this.

You can make your friendly AI ‘target’ this enemy by using the set focus node. You will need to then tell it to fire and move appropriately.

Hope this helps.

Thanks, I’ll try it.