A* Pathfinding Project  4.2.8
The A* Pathfinding Project for Unity 3D
SC2Avoidance Class Reference

Starcraft 2-like avoidance. More...

Detailed Description

Starcraft 2-like avoidance.

The main idea for this script is to

  • Reduce the local avoidance priority for agents that have reached their destination once.
  • Make agents stop if there is a high density of units around its destination.

'High density' is defined as: Take the circle with the center at the AI's destination and a radius such that the AI's current position is touching its border. Let 'A' be the area of that circle. Further let 'a' be the total area of all individual agents inside that circle. The agent should stop if a > A*0.6 or something like that. I.e if the agents inside the circle cover over 60% of the surface of the circle. The 60% figure can be modified.

Public Attributes

float densityFraction = 0.5f
 
bool returnAfterBeingPushedAway = true
 

Properties

bool reachedDestination [get]
 True if the agent has reached its destination. More...
 

Private Member Functions

float AgentDensityInCircle (Vector2 position, float radius)
 
void Awake ()
 
void CheckDestination ()
 
bool ShouldStop ()
 
void Update ()
 

Private Attributes

IAstarAI ai
 
const float MaximumCirclePackingDensity = 0.9069f
 See https://en.wikipedia.org/wiki/Circle_packing. More...
 
Vector3 prevDestination
 
bool reachedCurrentDestination
 
RVOController rvo
 
float timer1 = 0
 
float timer2 = 0
 

Static Private Attributes

static List< IAgentagentBuffer = new List<IAgent>()
 

Member Function Documentation

◆ AgentDensityInCircle()

float AgentDensityInCircle ( Vector2  position,
float  radius 
)
private

◆ Awake()

void Awake ( )
private

◆ CheckDestination()

void CheckDestination ( )
private

◆ ShouldStop()

bool ShouldStop ( )
private

◆ Update()

void Update ( )
private

Member Data Documentation

◆ agentBuffer

List<IAgent> agentBuffer = new List<IAgent>()
staticprivate

◆ ai

IAstarAI ai
private

◆ densityFraction

float densityFraction = 0.5f

◆ MaximumCirclePackingDensity

const float MaximumCirclePackingDensity = 0.9069f
private

◆ prevDestination

Vector3 prevDestination
private

◆ reachedCurrentDestination

bool reachedCurrentDestination
private

◆ returnAfterBeingPushedAway

bool returnAfterBeingPushedAway = true

◆ rvo

RVOController rvo
private

◆ timer1

float timer1 = 0
private

◆ timer2

float timer2 = 0
private

Property Documentation

◆ reachedDestination

bool reachedDestination
get

True if the agent has reached its destination.

If the agents destination changes this will return false until a new path has been calculated. Note that changing the destination every frame may cause this value to never return true.

True will be returned if the agent has stopped due to being close enough to the destination. This may be quite some distance away if there are many other agents around the destination.

See also
Pathfinding.IAstarAI.destination

The documentation for this class was generated from the following file: