Class SimulatorBurst
Extends
ISimulator
Public
Local Avoidance Simulator.
This class handles local avoidance simulation for a number of agents using Reciprocal Velocity Obstacles (RVO) and Optimal Reciprocal Collision Avoidance (ORCA).
This class will handle calculation of velocities from desired velocities supplied by a script. It is, however, not responsible for moving any objects in a Unity Scene. For that there are other scripts (see below).
Obstacles can be added and removed from the simulation, agents can also be added and removed at any time.
The implementation uses a sampling based algorithm with gradient descent to find the avoidance velocities.
You will most likely mostly use the wrapper class 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
Inner Types
Public Methods
Vector3 | position | See #IAgent.Position |
)
Add an agent at the specified position.
You can use the returned interface to read and write parameters and set for example radius and desired point to move to.
Vector3[] | vertices | |
float | height | |
bool | cycle=true | |
)
Vector3[] | vertices | |
float | height | |
Matrix4x4 | matrix | |
RVOLayer | layer=RVOLayer.DefaultObstacle | |
bool | cycle=true | |
)
void
ClearAgents
()
Removes all agents from the simulation.
IReadOnlyList<IAgent>
GetAgents
()
Get a list of all agents.
This is an internal list. I'm not going to be restrictive so you may access it since it is better for performance but please do not modify it since that can cause errors in the simulation.
Warning
Do not modify this list!
Get a list of all obstacles.
This is a list of obstacle vertices. Each vertex is part of a doubly linked list loop forming an obstacle polygon.
Warning
Do not modify this list!
void
OnDestroy
()
Frees all used memory.
Warning
You must call this when you are done with the simulator, otherwise some resources can linger and lead to memory leaks.
void
RemoveAgent
(
)
Removes a specified agent from this simulation.
The agent can be added again later by using AddAgent.
SimulatorBurst
(
bool | doubleBuffering | Use Double Buffering for calculations. Testing done with 5000 agents and 0.1 desired delta time showed that with double buffering enabled the game ran at 50 fps for most frames, dropping to 10 fps during calculation frames. But without double buffering it ran at around 10 fps all the time.
This will let threads calculate while the game progresses instead of waiting for the calculations to finish. |
MovementPlane | movementPlane | The plane that the movement happens in. XZ for 3D games, XY for 2D games. |
)
Create a new simulator.
Note
Will only have effect if using multithreading
void
Update
()
Should be called once per frame.
void
UpdateObstacles
()
Rebuilds the obstacle tree at next simulation frame.
Add and remove obstacle functions call this automatically.
Public Variables
int
AgentCount
Number of agents in the simulation.
bool
AnyAgentHasDebug
True if at least one agent had debug drawing enabled during the previous frame.
float
DesiredDeltaTime
Time in seconds between each simulation step.
This is the desired delta time, the simulation will never run at a higher fps than the rate at which the Update function is called.
bool
DoubleBuffering
Use double buffering.
bool
HardCollisions
Use hard collisions.
float
SymmetryBreakingBias
Bias agents to pass each other on the right side.
If the desired velocity of an agent puts it on a collision course with another agent or an obstacle its desired velocity will be rotated this number of radians (1 radian is approximately 57°) to the right. This helps to break up symmetries and makes it possible to resolve some situations much faster.
When many agents have the same goal this can however have the side effect that the group clustered around the target point may as a whole start to spin around the target point.
Recommended values are in the range of 0 to 0.2.
If this value is negative, the agents will be biased towards passing each other on the left side instead.
MovementPlane
movementPlane = MovementPlane.XZ
Determines if the XY (2D) or XZ (3D) plane is used for movement.
Obstacles in this simulation.
Internal simulation data.
Can be used if you need very high performance access to the agent data. Normally you would use the SimulatorBurst.Agent class instead (implements the IAgent interface).
Quadtree for this simulation.
Used internally by the simulation to perform fast neighbour lookups for each agent. Please only read from this tree, do not rebuild it since that can interfere with the simulation. It is rebuilt when necessary.
Internal simulation data.
Can be used if you need very high performance access to the agent data. Normally you would use the SimulatorBurst.Agent class instead (implements the IAgent interface).
Public Static Variables
const int
MaxNeighbourCount = 50
Private/Protected Members
void
AllocateAgentSpace
()
void
BlockUntilSimulationStepIsDone
()
Blocks until separate threads have finished with the current simulation step.
When double buffering is done, the simulation is performed in between frames.
void
CleanAndUpdateObstaclesIfNecessary
()
void
ScheduleCleanObstacles
()
void
UpdateInternal< T >
()
Action[]
agentPreCalculationCallbacks = new Action[0]
Agents in this simulation.
float
desiredDeltaTime = 0.05f
Inverse desired simulation fps.
int
numAgents = 0
Number of agents in this simulation.
Deprecated Members
Vector2 | position | See #IAgent.Position |
float | elevationCoordinate | See IAgent.ElevationCoordinate |
)
Add an agent at the specified position.
You can use the returned interface to read and write parameters and set for example radius and desired point to move to.