A* Pathfinding Project
4.1.20
The A* Pathfinding Project for Unity 3D
|
Internal agent for the RVO system. More...
Internal agent for the RVO system.
Usually you will interface with the IAgent interface instead.
Classes | |
struct | VO |
Velocity Obstacle. More... | |
class | VOBuffer |
Very simple list. More... | |
Public Member Functions | |
Agent (Vector3 pos) | |
void | BufferSwitch () |
Reads public properties and stores them in internal fields. | |
void | CalculateNeighbours () |
Populate the neighbours and neighbourDists lists with the closest agents to this agent. | |
void | ForceSetVelocity (Vector3 velocity) |
Set the current velocity of the agent. | |
void | PostCalculation () |
void | PreCalculation () |
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. | |
Public Member Functions inherited from IAgent | |
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. | |
Package Functions | |
void | CalculateVelocity (Pathfinding.RVO.Simulator.WorkerContext context) |
float | InsertAgentNeighbour (Agent agent, float rangeSq) |
Used by the Quadtree. | |
Package Attributes | |
bool | locked = false |
Agent | next |
Used internally for a linked list. | |
Vector3 | position |
float | radius |
Simulator | simulator |
Simulator which handles this agent. | |
Properties | |
float | AgentTimeHorizon [get, set] |
Max number of estimated seconds to look into the future for collisions with agents. | |
float | CalculatedSpeed [get, set] |
Optimal speed of the agent to avoid collisions. | |
Vector2 | CalculatedTargetPoint [get, set] |
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 | ElevationCoordinate [get, set] |
| |
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, set] |
Number of neighbours that the agent took into account during the last simulation step. | |
List< ObstacleVertex > | NeighbourObstacles [get] |
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 [get, 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. | |
Properties inherited from IAgent | |
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< ObstacleVertex > | NeighbourObstacles [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. | |
Private Member Functions | |
void | DrawVO (Vector2 circleCenter, float radius, Vector2 origin) |
Vector2 | EvaluateGradient (VOBuffer vos, Vector2 p, out float value) |
Evaluate gradient and value of the cost function at velocity p. | |
Vector3 | FromXZ (Vector2 p) |
(x, 0, y) | |
void | GenerateNeighbourAgentVOs (VOBuffer vos) |
void | GenerateObstacleVOs (VOBuffer vos) |
Vector2 | GradientDescent (VOBuffer vos, Vector2 sampleAround1, Vector2 sampleAround2) |
Vector2 | To2D (Vector3 p, out float elevation) |
Converts a 3D vector to a 2D vector in the movement plane. | |
Vector2 | ToXZ (Vector3 p) |
(x, z) | |
Vector2 | Trace (VOBuffer vos, Vector2 p, out float score) |
Traces the vector field constructed out of the velocity obstacles. | |
Static Private Member Functions | |
static bool | BiasDesiredVelocity (VOBuffer vos, ref Vector2 desiredVelocity, ref Vector2 targetPointInVelocitySpace, float maxBiasRadians) |
Bias towards the right side of agents. | |
static Color | Rainbow (float v) |
static float | Sqr (float x) |
Square a number. | |
Agent | ( | Vector3 | pos | ) |
|
staticprivate |
Bias towards the right side of agents.
Rotate desiredVelocity at most [value] number of radians. 1 radian ≈ 57° This breaks up symmetries.
The desired velocity will only be rotated if it is inside a velocity obstacle (VO). If it is inside one, it will not be rotated further than to the edge of it
The targetPointInVelocitySpace will be rotated by the same amount as the desired velocity
void BufferSwitch | ( | ) |
Reads public properties and stores them in internal fields.
This is required because multithreading is used and if another script updated the fields at the same time as this class used them in another thread weird things could happen.
Will also set CalculatedTargetPoint and CalculatedSpeed to the result which was last calculated.
void CalculateNeighbours | ( | ) |
Populate the neighbours and neighbourDists lists with the closest agents to this agent.
|
package |
|
private |
|
private |
Evaluate gradient and value of the cost function at velocity p.
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.
|
private |
(x, 0, y)
|
private |
|
private |
|
private |
|
package |
Used by the Quadtree.
void PostCalculation | ( | ) |
void PreCalculation | ( | ) |
|
staticprivate |
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.
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.
targetPoint | Target 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. |
desiredSpeed | Desired speed of the agent. In world units per second. The agent will try to move with this speed if possible. |
maxSpeed | Max 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). |
|
staticprivate |
Square a number.
|
private |
Converts a 3D vector to a 2D vector in the movement plane.
If movementPlane is XZ it will be projected onto the XZ plane and the elevation coordinate will be the Y coordinate otherwise it will be projected onto the XY plane and elevation will be the Z coordinate.
|
private |
(x, z)
|
private |
Traces the vector field constructed out of the velocity obstacles.
Returns the position which gives the minimum score (approximately).
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Desired target point - position.
|
private |
|
private |
|
private |
desiredVelocity in world space
|
private |
|
private |
|
private |
Elevation in the movementPlane.
|
private |
Position in the movementPlane.
|
package |
|
private |
|
private |
|
private |
|
private |
|
private |
|
package |
Used internally for a linked list.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
package |
|
package |
|
private |
|
package |
Simulator which handles this agent.
Used by this script as a reference and to prevent adding this agent to multiple simulations.
|
private |
Extra weight that walls will have.
|
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.
|
getset |
Optimal speed of the agent to avoid collisions.
The movement script should move towards CalculatedTargetPoint with this speed.
|
getset |
Optimal point to move towards to avoid collisions.
The movement script should move towards this point with a speed of CalculatedSpeed.
If necessary, you can convert the value to a world space position like this
|
getset |
Layer mask specifying which layers this agent will avoid.
You can set it as CollidesWith = RVOLayer.DefaultAgent | RVOLayer.Layer3 | RVOLayer.Layer6 ...
|
getset |
Draw debug information.
|
getset |
|
getset |
Height of the agent in world units.
Agents are modelled as circles/cylinders.
|
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.
|
getset |
Specifies the avoidance layer for this agent.
The CollidesWith mask on other agents will determine if they will avoid this agent.
|
getset |
Locked agents will be assumed not to move.
|
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.
|
getset |
Number of neighbours that the agent took into account during the last simulation step.
|
get |
|
getset |
Max number of estimated seconds to look into the future for collisions with obstacles.
|
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.
|
getset |
Callback which will be called right before avoidance calculations are started.
Used to update the other properties with the most up to date values
|
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:
|
getset |
Radius of the agent in world units.
Agents are modelled as circles/cylinders.