'How do I find the best location for an AOE ability
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
