A* Pathfinding Project  3.8.5
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
RVOController Class Reference

RVO Character Controller. More...

Detailed Description

RVO Character Controller.

Similar to Unity's CharacterController. It handles movement calculations and takes other agents into account. It does not handle movement itself, but allows the calling script to get the calculated velocity and use that to move the object using a method it sees fit (for example using a CharacterController, using transform.Translate or using a rigidbody).

public void Update () {
// Just some point far away
var targetPoint = transform.position + transform.forward * 100;
// Set the desired point to move towards using a desired speed of 10 and a max speed of 12
controller.SetTarget(targetPoint, 10, 12);
// Calculate how much to move during this frame
// This information is based on movement commands from earlier frames
// as local avoidance is calculated globally at regular intervals by the RVOSimulator component
var delta = controller.CalculateMovementDelta(transform.position, Time.deltaTime);
transform.position = transform.position + delta;
}

For documentation of many of the variables of this class: refer to the Pathfinding.RVO.IAgent interface.

Note
Requires a single RVOSimulator component in the scene
See Also
Pathfinding.RVO.IAgent
RVOSimulator
Local Avoidance
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 Awake ()
 
Vector3 CalculateMovementDelta (float deltaTime)
 Direction and distance to move in a single frame to avoid obstacles.
 
Vector3 CalculateMovementDelta (Vector3 position, float deltaTime)
 Direction and distance to move in a single frame to avoid obstacles.
 
void ForceSetVelocity (Vector3 velocity)
 Set the current velocity of the agent.
 
void Move (Vector3 vel)
 Set the desired velocity for the agent.
 
void OnDisable ()
 
void OnEnable ()
 
void SetCollisionNormal (Vector3 normal)
 Set the normal of a wall (or something else) the agent is currently colliding with.
 
void SetTarget (Vector3 pos, float speed, float maxSpeed)
 Set the target point for the agent to move towards.
 
void Teleport (Vector3 pos)
 Teleport the agent to a new position.
 
void Update ()
 

Public Attributes

float agentTimeHorizon = 2
 How far into the future to look for collisions with other agents.
 
float center
 Center of the agent relative to the pivot point of this game object.
 
RVOLayer collidesWith = (RVOLayer)(-1)
 Layer mask specifying which layers this agent will avoid.
 
bool debug
 Enables drawing debug information in the scene view.
 
float height = 1
 Height of the agent in world units.
 
RVOLayer layer = RVOLayer.DefaultAgent
 Specifies the avoidance layer for this agent.
 
bool locked
 A locked unit cannot move.
 
bool lockWhenNotMoving = true
 Automatically set locked to true when desired velocity is approximately zero.
 
int maxNeighbours = 10
 Max number of other agents to take into account.
 
MovementMode movementMode = MovementMode.XZ
 Determines if the XY (2D) or XZ (3D) plane is used for movement.
 
float neighbourDist = 10
 Maximum distance to other agents to take them into account for collisions.
 
float obstacleTimeHorizon = 2
 How far into the future to look for collisions with obstacles.
 
float priority = 0.5f
 How strongly other agents will avoid this agent.
 
float radius = 5
 Radius of the agent in world units.
 
float wallAvoidFalloff = 1
 How much the wallAvoidForce decreases with distance.
 
float wallAvoidForce = 1
 An extra force to avoid walls.
 

Protected Member Functions

void UpdateAgentProperties ()
 

Properties

Vector3 position [get]
 Current position of the agent.
 
IAgent rvoAgent [get, set]
 Reference to the internal agent.
 
Simulator simulator [get, set]
 Reference to the rvo simulator.
 
Vector3 velocity [get]
 Current calculated velocity of the agent.
 

Private Member Functions

void OnDrawGizmos ()
 
void OnDrawGizmosSelected ()
 
Vector2 To2D (Vector3 p)
 
Vector2 To2D (Vector3 p, out float elevation)
 
Vector3 To3D (Vector2 p, float elevationCoordinate)
 

Static Private Member Functions

static void DrawCircle (Vector3 p, float radius, float a0, float a1)
 
static void DrawCylinder (Vector3 p, Vector3 up, float height, float radius)
 

Private Attributes

Transform tr
 Cached tranform component.
 

Static Private Attributes

static RVOSimulator cachedSimulator
 To avoid having to use FindObjectOfType every time.
 
static readonly Color GizmoColor = new Color(240/255f, 213/255f, 30/255f)
 

Member Function Documentation

void Awake ( )
Vector3 CalculateMovementDelta ( float  deltaTime)

Direction and distance to move in a single frame to avoid obstacles.

Parameters
deltaTimeHow far to move [seconds]. Usually set to Time.deltaTime.
Vector3 CalculateMovementDelta ( Vector3  position,
float  deltaTime 
)

Direction and distance to move in a single frame to avoid obstacles.

Parameters
positionPosition of the agent.
deltaTimeHow far to move [seconds]. Usually set to Time.deltaTime.
static void DrawCircle ( Vector3  p,
float  radius,
float  a0,
float  a1 
)
staticprivate
static void DrawCylinder ( Vector3  p,
Vector3  up,
float  height,
float  radius 
)
staticprivate
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.

void Move ( Vector3  vel)

Set the desired velocity for the agent.

Note that this is a velocity (units/second), not a movement delta (units/frame).

This is assumed to stay the same until something else is requested (as opposed to being reset every frame).

Note
In most cases the SetTarget method is better to use
See Also
SetTarget
void OnDisable ( )
void OnDrawGizmos ( )
private
void OnDrawGizmosSelected ( )
private
void OnEnable ( )
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 SetTarget ( Vector3  pos,
float  speed,
float  maxSpeed 
)

Set the target point for the agent to move towards.

Similar to the Move method but this is more flexible. It is also better to use near the end of the path as when using the Move method the agent does not know where to stop, so it may overshoot the target. When using this method the agent will not overshoot the target.

The target point is assumed to stay the same until something else is requested (as opposed to being reset every frame).

Parameters
posPoint in world space to move towards.
speedDesired speed in world units per second.
maxSpeedMaximum speed in world units per second. The agent will use this speed if it is necessary to avoid collisions with other agents.
See Also
Move
void Teleport ( Vector3  pos)

Teleport the agent to a new position.

The agent will be moved instantly and not show ugly interpolation artifacts during a split second. Manually changing the position of the transform will in most cases be picked up as a teleport automatically by the script.

During the simulation frame the agent was moved manually, local avoidance cannot fully be applied to the agent, so try to avoid using it too much or local avoidance quality will degrade.

Vector2 To2D ( Vector3  p)
private
Vector2 To2D ( Vector3  p,
out float  elevation 
)
private
Vector3 To3D ( Vector2  p,
float  elevationCoordinate 
)
private
void Update ( )
void UpdateAgentProperties ( )
protected

Member Data Documentation

float agentTimeHorizon = 2

How far into the future to look for collisions with other agents.

RVOSimulator cachedSimulator
staticprivate

To avoid having to use FindObjectOfType every time.

float center

Center of the agent relative to the pivot point of this game object.

RVOLayer collidesWith = (RVOLayer)(-1)

Layer mask specifying which layers this agent will avoid.

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

This can be very useful in games which have multiple teams of some sort. For example you usually want the agents in one team avoid each other, but you do not want them to avoid the enemies.

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

Enables drawing debug information in the scene view.

readonly Color GizmoColor = new Color(240/255f, 213/255f, 30/255f)
staticprivate
float height = 1

Height of the agent in world units.

RVOLayer layer = RVOLayer.DefaultAgent

Specifies the avoidance layer for this agent.

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

bool locked

A locked unit cannot move.

Other units will still avoid it but avoidance quality is not the best.

bool lockWhenNotMoving = true

Automatically set locked to true when desired velocity is approximately zero.

This prevents other units from pushing them away when they are supposed to e.g block a choke point.

int maxNeighbours = 10

Max number of other agents to take into account.

A smaller value can reduce CPU load, a higher value can lead to better local avoidance quality.

MovementMode movementMode = MovementMode.XZ

Determines if the XY (2D) or XZ (3D) plane is used for movement.

float neighbourDist = 10

Maximum distance to other agents to take them into account for collisions.

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

float obstacleTimeHorizon = 2

How far into the future to look for collisions with obstacles.

float priority = 0.5f

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 an agent with a much lower priority than another agent will avoid the other agent in a way similar to if the other agent was a moving obstacle.

float radius = 5

Radius of the agent in world units.

Transform tr
private

Cached tranform component.

float wallAvoidFalloff = 1

How much the wallAvoidForce decreases with distance.

The strenght of avoidance is:

str = 1/dist*wallAvoidFalloff
See Also
wallAvoidForce
Todo:
This feature is currently disabled
float wallAvoidForce = 1

An extra force to avoid walls.

This can be good way to reduce "wall hugging" behaviour.

Todo:
This feature is currently disabled

Property Documentation

Vector3 position
get

Current position of the agent.

IAgent rvoAgent
getset

Reference to the internal agent.

Simulator simulator
getset

Reference to the rvo simulator.

Vector3 velocity
get

Current calculated velocity of the agent.

This is not necessarily the velocity the agent is actually moving with but it is the velocity that the RVO system has calculated is best for avoiding obstacles and reaching the target.

See Also
CalculateMovementDelta

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