cxong / cdogs-sdl

Classic overhead run-and-gun game
https://cxong.github.io/cdogs-sdl/
GNU General Public License v2.0
898 stars 114 forks source link

Cover/evasion #24

Open cxong opened 11 years ago

cxong commented 11 years ago

AI to understand cover, and evasion, i.e. sliding away from player's bullets.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

cxong commented 10 years ago

There's a conflict between this and movement/targeting (#23), especially if two AIs are using the same weapon. That is, to avoid the enemy's line of fire, you also give yourself a bad position from which to fire.

It may be possible to resolve this conflict by having "aggressive" and "defensive" AIs, where the former will prioritise getting into a good firing position over evasion, and vice versa. For AIs using different weapons, the AI can prefer evasion until it moves close enough for its weapon's range.

There's still a potential deadlock between two defensive AIs both trying to move outside each other's line of fire, which will be interesting to see :laughing:

cxong commented 10 years ago

This can also be generalised to avoid explosions, flames etc.

cxong commented 9 years ago

Added AI running away from dangerous bullets, like flames and fireballs. This works quite well because these things tend to be slower than even normal walking speed, although frags aren't evaded well, but then again these are hard to avoid in general.

Avoiding regular bullets would be harder though; not only does the AI need to look at a bigger radius, bigger if there are fast bullets, but they will need to side-step instead of run directly away. This requires a bit of trig, taking into account the bullet's trajectory, and to figure out if it's better to step to the left or right. Also, due to the abundance of bullets, it would be impractical to run away all the time - this action is a short-circuiting one for the dangerous bullets - so the AI needs to be able to do other things whilst dodging bullets.

One idea is to have the AI selectively dodge bullets. Another is for the dodge action to be of limited short circuiting - it will dodge only if the AI will not try to do some more important thing, like shooting.

It would be nice to also dodge friendly bullets, as an alternate way of solving #295

cxong commented 4 years ago

One method of doing this is:

  1. Find all bullets within radius
  2. Filter by those that will hit
    • Special logic required for grenades - want to stay away from explosion
  3. Sort based on a score:
    • Damage
    • Whether it's from a friendly or player
    • Time to hit
  4. For the top N bullets, find a safe direction and move there
    • To simplify, could just take the most significant bullet and attempt to sidestep it