- Home /
How to target an AOE ability to maximize hits
I'm making a game in unity3d. I have an AI agent that has a " "targetFinder" method to decide who it will attack. For basic "nearest enemy", it's pretty straightforward:
/* TargetFinder
Finds the closest enemy */
Transform TargetFinder(Transform source) {
GameObject[] EnemiesInScene = GetEnemies();
enemies = enemies.OrderBy(
(GameObject g) => Vector3.Distance(g.transform.position, source)
).ToArray();
return enemies.Length == 0 ? null : enemies[0].transform;
}
However, let's say I want to give the AI a "fireball" AOE attack, which does damage in a radius and travels from the enemy to a fixed point in the scene. I'd want some sort of method like:
/* TargetFinder
Finds the transform T within RANGE of SOURCE that maximizes
The number of enemy units within RADIUS of T */
Transform TargetFinder(Transform source, float range, float radius) {
GameObject[] EnemiesInScene = GetEnemies();
// ???
return T;
}
Given the enemies, what's the best way to find T? I was imagining a few ideas, but they all seemed very brute-force (e.g. instantiating a bunch of colliders, or doing some sort of topography and picking the highest point)
Would love any insight on if there's any algorithmic or unity-based approach to solving this targeting problem
Your answer
Follow this Question
Related Questions
Ai finding target after spawning 2 Answers
Ai Targetting feet instead of my body 2 Answers
faster target selection 2 Answers
AI Player detect without having a target before detect. 0 Answers
2d AI: enemy targeting c# 2 Answers