To determine the direction a weighted sum equation is used currently, roughly based on the boid algorithm to produce flocking behavior, of the form:
boidDirection = weightAvoidance * avoidanceDirection + weightAttack * attackDirection + weightAlignment * alignmentDirection + weightCohesion * cohesionDirection
While this AI seems to excel in 95% of scenarios, it fails miserably when the enemy is trapped between the player and a surface because I'm apparently doing a lousy job of determining the avoidance direction vector.
The current formula I use to calculate the avoidanceDirection vector is:
1) The enemy knows the position of other nearby ships and uses explorative raycasting in a forward facing cone to "look" ahead for collision avoidance with more complex geometry.
2) It then tries to avoid all of these things by calculating the direction it should travel as the sum of vectors away from each nearby ship or raycast intersection (weighting these avoidance vectors relative to distance). This can yield a different direction every frame as a result of new raycast discoveries (causing the jerking behavior described below).
This works well, except in the scenario where the player chases an enemy toward a "wall" (e.g a flat or concave surface on the hull of a much larger ship), and once the enemy "sees" the wall, it jerks around indecisively as it tries to find a clear direction to turn, but it's raycasts just show more wall ahead everywhere it looks. After jerking around indecisively for a few seconds the enemy comically flies into the wall because it couldn't find a good direction to turn.
This diagram essentially shows what this looks like from the perspective of the enemy. It sees things to avoid everywhere in front, but it must head towards all those things for a short while as it changes direction to get to the safe direction (green). As the enemy turns towards the chosen vector (green), it sees more raycast collisions in that direction, causing it to choose a new direction to go because those new raycasts suggest it should choose a different path (indecisive behavior).
Any suggestions for an algorithm that would choose the green vector consistently and not indecisively change direction?
Edited by jsuffolk, 23 November 2012 - 02:13 PM.