A* Pathfinding Project  4.1.20
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
IAgent Interface Reference

Exposes properties of an Agent class. More...

Detailed Description

Exposes properties of an Agent class.

See Also
RVOController
RVOSimulator
A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here

Public Member Functions

void ForceSetVelocity (Vector3 velocity)
 Set the current velocity of the agent.
 
void SetCollisionNormal (Vector3 normal)
 Set the normal of a wall (or something else) the agent is currently colliding with.
 
void SetMovementPlane (IMovementPlane movementPlane)
 Set the plane in which the agent should move.
 
void SetTarget (Vector3 targetPoint, float desiredSpeed, float maxSpeed)
 Point towards which the agent should move.
 

Properties

float AgentTimeHorizon [get, set]
 Max number of estimated seconds to look into the future for collisions with agents.
 
float CalculatedSpeed [get]
 Optimal speed of the agent to avoid collisions.
 
Vector2 CalculatedTargetPoint [get]
 Optimal point to move towards to avoid collisions.
 
RVOLayer CollidesWith [get, set]
 Layer mask specifying which layers this agent will avoid.
 
bool DebugDraw [get, set]
 Draw debug information.
 
float Height [get, set]
 Height of the agent in world units.
 
float HeightOffset [get, set]
 Offset of the agent position along the up direction.
 
RVOLayer Layer [get, set]
 Specifies the avoidance layer for this agent.
 
bool Locked [get, set]
 Locked agents will be assumed not to move.
 
int MaxNeighbours [get, set]
 Max number of agents to take into account.
 
IMovementPlane MovementPlane [get]
 Plane in which the agent is moving.
 
int NeighbourCount [get]
 Number of neighbours that the agent took into account during the last simulation step.
 
List< ObstacleVertexNeighbourObstacles [get]
 List of obstacle segments which were close to the agent during the last simulation step.
 
float ObstacleTimeHorizon [get, set]
 Max number of estimated seconds to look into the future for collisions with obstacles.
 
Vector3 Position [get, set]
 Position of the agent.
 
System.Action PreCalculationCallback [set]
 Callback which will be called right before avoidance calculations are started.
 
float Priority [get, set]
 How strongly other agents will avoid this agent.
 
float Radius [get, set]
 Radius of the agent in world units.
 

Member Function Documentation

void ForceSetVelocity ( Vector3  velocity)

Set the current velocity of the agent.

This will override the local avoidance input completely. It is useful if you have a player controlled character and want other agents to avoid it.

Calling this method will mark the agent as being externally controlled for 1 simulation step. Local avoidance calculations will be skipped for the next simulation step but will be resumed after that unless this method is called again.

Note
The velocity will be projected on the current movement plane.
void SetCollisionNormal ( Vector3  normal)

Set the normal of a wall (or something else) the agent is currently colliding with.

This is used to make the RVO system aware of things like physics or an agent being clamped to the navmesh. The velocity of this agent that other agents observe will be modified so that there is no component into the wall. The agent will however not start to avoid the wall, for that you will need to add RVO obstacles.

This value will be cleared after the next simulation step, normally it should be set every frame when the collision is still happening.

void SetMovementPlane ( IMovementPlane  movementPlane)

Set the plane in which the agent should move.

After the next calculation step, the MovementPlane property will be set to an identical plane.

See Also
#GraphTransform.xyPlane
#GraphTransform.xzPlane
void SetTarget ( Vector3  targetPoint,
float  desiredSpeed,
float  maxSpeed 
)

Point towards which the agent should move.

Usually you set this once per frame. The agent will try move as close to the target point as possible. Will take effect at the next simulation step.

Note
The system assumes that the agent will stop when it reaches the target point so if you just want to move the agent in a particular direction, make sure that you set the target point a good distance in front of the character as otherwise the system may not avoid colisions that well. What would happen is that the system (in simplified terms) would think that the agents would stop before the collision and thus it wouldn't slow down or change course. See the image below. In the image the desiredSpeed is the length of the blue arrow and the target point is the point where the black arrows point to. In the upper case the agent does not avoid the red agent (you can assume that the red agent has a very small velocity for simplicity) while in the lower case it does.
If you are following a path a good way to pick the target point is to set it to
targetPoint = directionToNextWaypoint.normalized * remainingPathDistance
Where remainingPathDistance is the distance until the character would reach the end of the path. This works well because at the end of the path the direction to the next waypoint will just be the direction to the last point on the path and remainingPathDistance will be the distance to the last point in the path, so targetPoint will be set to simply the last point in the path. However when remainingPathDistance is large the target point will be so far away that the agent will essentially be told to move in a particular direction, which is precisely what we want.
Parameters
targetPointTarget point in world space (XZ plane or XY plane depending on if the simulation is configured for 2D or 3D). Note that this is a Vector2, not a Vector3 since the system simulates everything internally in 2D. So if your agents move in the XZ plane you will have to supply it as a Vector2 with (x,z) coordinates.
desiredSpeedDesired speed of the agent. In world units per second. The agent will try to move with this speed if possible.
maxSpeedMax speed of the agent. In world units per second. If necessary (for example if another agent is on a collision trajectory towards this agent) the agent can move at this speed. Should be at least as high as desiredSpeed, but it is recommended to use a slightly higher value than desiredSpeed (for example desiredSpeed*1.2).

Property Documentation

float AgentTimeHorizon
getset

Max number of estimated seconds to look into the future for collisions with agents.

As it turns out, this variable is also very good for controling agent avoidance priorities. Agents with lower values will avoid other agents less and thus you can make 'high priority agents' by giving them a lower value.

float CalculatedSpeed
get

Optimal speed of the agent to avoid collisions.

The movement script should move towards CalculatedTargetPoint with this speed.

Vector2 CalculatedTargetPoint
get

Optimal point to move towards to avoid collisions.

The movement script should move towards this point with a speed of CalculatedSpeed.

Note
This is a Vector2, not a Vector3. The value is relative to the MovementPlane.

If necessary, you can convert the value to a world space position like this

var elevation;
agent.MovementPlane.ToPlane(agent.Position, out elevation);
var worldSpaceTargetPoint = agent.MovementPlane.ToWorld(agent.CalculatedTargetPoint, elevation);
See Also
RVOController.CalculateMovementDelta.
RVOLayer CollidesWith
getset

Layer mask specifying which layers this agent will avoid.

You can set it as CollidesWith = RVOLayer.DefaultAgent | RVOLayer.Layer3 | RVOLayer.Layer6 ...

See Also
http://en.wikipedia.org/wiki/Mask_(computing)
bool DebugDraw
getset

Draw debug information.

Note
Will always draw debug info in the XZ plane even if Pathfinding.RVO.Simulator.movementPlane is set to XY.
Ignored if multithreading on the simulator component has been enabled since Unity's Debug API can only be called from the main thread.
float Height
getset

Height of the agent in world units.

Agents are modelled as circles/cylinders.

float HeightOffset
getset

Offset of the agent position along the up direction.

This determines where the base of the agent collision cylinder is relative to the Position. If this is zero, then the base of the cylinder is at Position, but you might for example want the position to be at the center of the cylinder. In that case you can set this to -0.5 * Height.

RVOLayer Layer
getset

Specifies the avoidance layer for this agent.

The CollidesWith mask on other agents will determine if they will avoid this agent.

bool Locked
getset

Locked agents will be assumed not to move.

int MaxNeighbours
getset

Max number of agents to take into account.

Decreasing this value can lead to better performance, increasing it can lead to better quality of the simulation.

Plane in which the agent is moving.

The CalculatedTargetPoint is relative to this plane.

int NeighbourCount
get

Number of neighbours that the agent took into account during the last simulation step.

List<ObstacleVertex> NeighbourObstacles
get

List of obstacle segments which were close to the agent during the last simulation step.

Can be used to apply additional wall avoidance forces for example. Segments are formed by the obstacle vertex and its .next property.

Bug:
Always returns null
float ObstacleTimeHorizon
getset

Max number of estimated seconds to look into the future for collisions with obstacles.

Vector3 Position
getset

Position of the agent.

The agent does not move by itself, a movement script has to be responsible for reading the CalculatedTargetPoint and CalculatedSpeed properties and move towards that point with that speed. This property should ideally be set every frame.

System.Action PreCalculationCallback
set

Callback which will be called right before avoidance calculations are started.

Used to update the other properties with the most up to date values

float Priority
getset

How strongly other agents will avoid this agent.

Usually a value between 0 and 1. Agents with similar priorities will avoid each other with an equal strength. If an agent sees another agent with a higher priority than itself it will avoid that agent more strongly. In the extreme case (e.g this agent has a priority of 0 and the other agent has a priority of 1) it will treat the other agent as being a moving obstacle. Similarly if an agent sees another agent with a lower priority than itself it will avoid that agent less.

In general the avoidance strength for this agent is:

if this.priority > 0 or other.priority > 0:
avoidanceStrength = other.priority / (this.priority + other.priority);
else:
avoidanceStrength = 0.5
float Radius
getset

Radius of the agent in world units.

Agents are modelled as circles/cylinders.


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