NavAI Documentation
NavAI.Obstacleabstract

Inherits MonoBehaviour.

Inherited by NavAI.CircleObstacle, NavAI.PolygonObstacle, and NavAI.RectangleObstacle.

Public Types

enum  CarveType { CarveType.CarveHeightmap, CarveType.CarveTriangulation, CarveType.DontCarve, CarveType.IgnoreObstacle }
 
enum  ObstacleType { ObstacleType.Static, ObstacleType.Dynamic }
 

Public Member Functions

abstract void Draw (Color color)
 
abstract Vector3 [] GetWorldPolygon ()
 
abstract void GetWorldPolygon (System.Collections.Generic.IList< Vector3 > polygon)
 
abstract void GetWorldPolygon (Vector3[] polygon)
 
abstract Vector2 [] GetZonePolygon ()
 
abstract void GetZonePolygon (System.Collections.Generic.IList< Vector2 > polygon)
 
abstract void GetZonePolygon (Vector2[] polygon)
 
virtual void Load (NavigationZone zone=null)
 

Protected Attributes

bool carveOnlyStationary
 
CarveType carveType
 
float localAngle
 
float localCos
 
Vector2 localPosition
 
float localRadius
 
Vector2 localScale
 
float localSin
 
float moveThreshold
 
int noVertices
 
float timeToStationary
 
ObstacleType type
 
float zoneAngle
 
float zoneCos
 
Vector2 zonePosition
 
Vector2 zoneScale
 
float zoneSin
 

Properties

bool CarveHeightMap [get]
 
bool CarveOnlyStationary [get, protected set]
 
bool CarveTriangulation [get]
 
bool Dirty [get, set]
 
bool DontCarve [get]
 
bool IgnoreObstacle [get]
 
bool IsActive [get]
 
bool IsCarved [get]
 
bool IsDynamic [get]
 
bool IsStatic [get]
 
bool IsStationary [get]
 
float LocalAngle [get]
 
Vector2 LocalPosition [get]
 
Vector2 LocalScale [get]
 
float MoveThreshold [get, protected set]
 
int NoVertices [get, protected set]
 
CarveType ObstCarveType [get, protected set]
 
ObstacleType ObstType [get, protected set]
 
float SqrMoveThreshold [get]
 
abstract Vector2 this[int i] [get]
 
float TimeToStationary [get, protected set]
 
float WorldAngle [get]
 
Vector3 WorldPosition [get]
 
float WorldRadius [get]
 
Vector3 WorldScale [get]
 
NavigationZone Zone [get, set]
 
float ZoneAngle [get]
 
Vector2 ZonePosition [get]
 
float ZoneRadius [get]
 
Vector2 ZoneScale [get]
 

Member Enumeration Documentation

◆ CarveType

Carve type of the obstacle.

Enumerator
CarveHeightmap 

Obstacle is carved on the heightmap. This option will create a navmesh surface over the obstacle. Dynamic obstacles cannot carve the heightmap.

CarveTriangulation 

Obstacle is carved on the triangulation. The triangulation is used for pathfinding and other systems.

DontCarve 

Obstacle is not carved on the triangulation. Agents will avoid the obstacle using local collision avoidance only.

IgnoreObstacle 

Obstacle will be completely ignored by the navigation algorithms.

◆ ObstacleType

Type of obstacle according to how it is treated by the mesh.

Enumerator
Static 

Obstacle transform and properties cannot be changed at runtime.

Dynamic 

Obstacle transform and properties can be changed at runtime.

Member Function Documentation

◆ Draw()

abstract void NavAI.Obstacle.Draw ( Color  color)
pure virtual

Draws the obstacle collider.

Parameters
colorMaterial color.

Implemented in NavAI.CircleObstacle, NavAI.PolygonObstacle, and NavAI.RectangleObstacle.

◆ GetWorldPolygon() [1/3]

abstract Vector3 [] NavAI.Obstacle.GetWorldPolygon ( )
pure virtual

Gets the obstacle collider polygon in the world space.

Returns
An array with the collider vertices.

Implemented in NavAI.CircleObstacle, NavAI.PolygonObstacle, and NavAI.RectangleObstacle.

◆ GetWorldPolygon() [2/3]

abstract void NavAI.Obstacle.GetWorldPolygon ( System.Collections.Generic.IList< Vector3 >  polygon)
pure virtual

Gets the obstacle collider polygon in the world space.

Parameters
polygonA list to be filled with the collider vertices. The list must have write permission.

◆ GetWorldPolygon() [3/3]

abstract void NavAI.Obstacle.GetWorldPolygon ( Vector3 []  polygon)
pure virtual

Gets the obstacle colider polygon in the world space.

Parameters
polygonAn array to be filled with the collider vertices. Array length must match the number of vertices of the obstacle.

Implemented in NavAI.CircleObstacle, NavAI.PolygonObstacle, and NavAI.RectangleObstacle.

◆ GetZonePolygon() [1/3]

abstract Vector2 [] NavAI.Obstacle.GetZonePolygon ( )
pure virtual

Gets the obstacle collider polygon in it's zone local space.

Returns
An array containg the collider vertices.

Implemented in NavAI.CircleObstacle, NavAI.PolygonObstacle, and NavAI.RectangleObstacle.

◆ GetZonePolygon() [2/3]

abstract void NavAI.Obstacle.GetZonePolygon ( System.Collections.Generic.IList< Vector2 >  polygon)
pure virtual

Gets the obstacle collider polygon in it's zone local space.

Parameters
polygonA list to be filled with the collider vertices. The list must have write permission.

◆ GetZonePolygon() [3/3]

abstract void NavAI.Obstacle.GetZonePolygon ( Vector2 []  polygon)
pure virtual

Gets the obstacle colider polygon in it's zone local space.

Parameters
polygonAn array to be filled with the collider vertices. Array length must match the number of vertices of the obstacle.

Implemented in NavAI.CircleObstacle, NavAI.PolygonObstacle, and NavAI.RectangleObstacle.

◆ Load()

virtual void NavAI.Obstacle.Load ( NavigationZone  zone = null)
virtual

Loads the obstacle runtime variables.

Parameters
zoneZone the obstacle is in.

This method is used internally to load the obstacle when it adquires a new zone, and also by the editor inspectors. There is no need for the user to use this function.

Reimplemented in NavAI.CircleObstacle.

Member Data Documentation

◆ carveOnlyStationary

bool NavAI.Obstacle.carveOnlyStationary
protected

Toggles carving the obstacle only when it is stationary.

If enabled, then the obstacle will be temporarely added to the obstacles KD-Tree while moving, and will be automatically remvoed from the tree and added to the navmesh triangulation when it becomes stationary.

◆ carveType

CarveType NavAI.Obstacle.carveType
protected

Obstacle carve type.

CarveHeightmap: The obstacle will be carved on the heightmap, generating a navmesh surface over it.

CarveTrianguylatiion: The obstacle will be carved on the triangulation, allowing the pathfinder and other systems to deal with this obstacle intelligently.

DontCarve: The obstacle will not be carved on the triangulation and will be kept on the obstacles KD-Tree. This means that agents will avoid this obstacle using local collision avoidance only, and the pathfinder will not be able to calcualte a path around this obstacle.

◆ localAngle

float NavAI.Obstacle.localAngle
protected

Degrees up axis (Y) angle of the obstacle in it's local space.

This is the equivalent of an offset for the obstacle collider Y angle.

◆ localCos

float NavAI.Obstacle.localCos
protected

Cossin of the localAngle.

◆ localPosition

Vector2 NavAI.Obstacle.localPosition
protected

Position of the obstacle in the obstacle local space (x, z).

This is the equivalent of an offset for the obstacle collider position.

◆ localRadius

float NavAI.Obstacle.localRadius
protected

Radius in meters of the bounding ball in the obstacle local space.

The bounding ball is a circle centered at the obstacle center that contains all obstacle collider points.

◆ localScale

Vector2 NavAI.Obstacle.localScale
protected

Scale of the obstacle in it's local space (x, z)

This is the equivalent of the obstacle collider size.

◆ localSin

float NavAI.Obstacle.localSin
protected

Sin of the localAngle.

◆ moveThreshold

float NavAI.Obstacle.moveThreshold
protected

Movement threshold in meters for the obstacle to be considered moving.

This is only used by dyanmic obstacles. Obstacles that have moved over the last frame will be flagged as dirty for the zone to update the triangulation or the obstacles KD-Tree.

Increasing this value can improve performance if there are too many dynamic obstacles in the scene.

◆ noVertices

int NavAI.Obstacle.noVertices
protected

Number of vertices of the obstacle collider.

This is unused by obstacles that carve heightmap.

◆ timeToStationary

float NavAI.Obstacle.timeToStationary
protected

Time not moving in seconds for the obstacle to be considered stationary.

This variable is used by dynamic obstacles flagged with carveOnlyStationary to determine when to carve the obstacle.

◆ type

ObstacleType NavAI.Obstacle.type
protected

Type of the obstacle as static or dynamic.

A static obstacle will be carved either on the heightmap or on the triangulation, and will not be able to change at runtime.

Dynamic obstacles cannot be carved on the heightmap, but can have their transform changed at runtime.

◆ zoneAngle

float NavAI.Obstacle.zoneAngle
protected

Up axis (Y) angle in degrees.

For performance and simplicty, we only keep track of the Y axis angle of obstacles. This means that rotating the obstacle using the X and Z axis will have no effect on the obstacle collider.

This field is only used by dynamic obstacles.

◆ zoneCos

float NavAI.Obstacle.zoneCos
protected

Cossin of the zoneAngle.

This variable is stored to prevent recalculating the cossin when there are no changes to the angle.

◆ zonePosition

Vector2 NavAI.Obstacle.zonePosition
protected

Position of the obstacle on the zone in the local zone coordinate system.

This is equivalent of Zone.WorldToLocalPoint(transform.position).

This field is only used by dynamic obstacles.

◆ zoneScale

Vector2 NavAI.Obstacle.zoneScale
protected

Scale of the obstacle on it's own local space (x, z).

Since the obstacle collider is roughly 2D, there is no need to keep track of the sacle on the Y axis.

It would be mathematically correct for this scale to affect the obstacle collider scaling on the zone coordinate system, but that would cause distortion of the obstacle collider, which is not the intention. Using this scale on the obstacle local space simply makes the collider larger, without distorting it.

This field is only used by dynamic obstacles.

◆ zoneSin

float NavAI.Obstacle.zoneSin
protected

Sin of the zoneAngle.

This variable is stored to prevent recalculating the cossin when there are no changes to the angle.

Property Documentation

◆ CarveHeightMap

bool NavAI.Obstacle.CarveHeightMap
get

Gets true if the obstacle carve type is CarveHeightmap.

◆ CarveOnlyStationary

bool NavAI.Obstacle.CarveOnlyStationary
getprotected set

Gets or sets carving the obstacle only when it is stationary.

If enabled, then the obstacle will be temporarely added to the obstacles KD-Tree while moving, and will be automatically remvoed from the tree and added to the navmesh triangulation when it becomes stationary.

◆ CarveTriangulation

bool NavAI.Obstacle.CarveTriangulation
get

Gets true if the obstacle carve type is CarveTriangulation.

◆ Dirty

bool NavAI.Obstacle.Dirty
getset

Gets or sets if the obstacle is dirty.

◆ DontCarve

bool NavAI.Obstacle.DontCarve
get

Gets true if the obstacle carve type is DontCarve.

◆ IgnoreObstacle

bool NavAI.Obstacle.IgnoreObstacle
get

Gets true if the obstacle carve type is IgnoreObstacle.

◆ IsActive

bool NavAI.Obstacle.IsActive
get

Gets trye if the obstacle is active.

◆ IsCarved

bool NavAI.Obstacle.IsCarved
get

Gets true if the obstacle is carved on the triangulation.

◆ IsDynamic

bool NavAI.Obstacle.IsDynamic
get

Gets true if the obstacle type is dynamic.

◆ IsStatic

bool NavAI.Obstacle.IsStatic
get

Gets true if the obstacle type is static.

◆ IsStationary

bool NavAI.Obstacle.IsStationary
get

Gets true if the obstacle is currently stationary.

◆ LocalAngle

float NavAI.Obstacle.LocalAngle
get

Gets the Y angle of the obstacle in it's local space.

This is the equivalent of the obstacle collider angle offset.

◆ LocalPosition

Vector2 NavAI.Obstacle.LocalPosition
get

Gets the position of the obstacle in it's local space (X, Z).

This is the equivalent of the obstacle collider position offset.

◆ LocalScale

Vector2 NavAI.Obstacle.LocalScale
get

Gets the scale of the obstacle in it's local space (X, Z).

This is the equivalent of the obstacle collider size.

◆ MoveThreshold

float NavAI.Obstacle.MoveThreshold
getprotected set

Gets or sets the movement threshold in meters for the obstacle to be considered moving.

This is only used by dyanmic obstacles. Obstacles that have moved over the last frame will be flagged as dirty for the zone to update the triangulation or the obstacles KD-Tree.

Increasing this value can improve performance if there are too many dynamic obstacles in the scene.

◆ NoVertices

int NavAI.Obstacle.NoVertices
getprotected set

Gets the number of vertices of the obstacle.

This propriety is not used by obstacles that carve the heightmap.

◆ ObstCarveType

CarveType NavAI.Obstacle.ObstCarveType
getprotected set

Gets or sets the obstacle carve type.

CarveHeightmap: The obstacle will be carved on the heightmap, generating a navmesh surface over it.

CarveTrianguylatiion: The obstacle will be carved on the triangulation, allowing the pathfinder and other systems to deal with this obstacle intelligently.

DontCarve: The obstacle will not be carved on the triangulation and will be kept on the obstacles KD-Tree. This means that agents will avoid this obstacle using local collision avoidance only, and the pathfinder will not be able to calcualte a path around this obstacle.

◆ ObstType

ObstacleType NavAI.Obstacle.ObstType
getprotected set

Gets or sets the type of the obstacle.

A static obstacle will be carved either on the heightmap or on the triangulation, and will not be able to change at runtime.

Dynamic obstacles cannot be carved on the heightmap, but can have their transform changed at runtime.

◆ SqrMoveThreshold

float NavAI.Obstacle.SqrMoveThreshold
getprotected

Gets the movement threshold squared.

◆ this[int i]

abstract Vector2 NavAI.Obstacle.this[int i]
get

Gets the vertex[i] of the obstacle.

Parameters
iIndex of the vertex.
Returns
The vertex i of the obstacle collider.

◆ TimeToStationary

float NavAI.Obstacle.TimeToStationary
getprotected set

Gets or sets the time not moving in seconds for the obstacle to be considered stationary.

This variable is used by dynamic obstacles flagged with carveOnlyStationary to determine when to carve the obstacle.

◆ WorldAngle

float NavAI.Obstacle.WorldAngle
get

Gets the world Y angle of the obstacle in degrees.

This will be different from transform.position if the obstacle has a localAngle other than zero.

◆ WorldPosition

Vector3 NavAI.Obstacle.WorldPosition
get

Gets the world position of the obstacle.

This will be different from transform.position if the obstacle has a localPosition other than zero.

◆ WorldRadius

float NavAI.Obstacle.WorldRadius
get

Gets the world radius in meters of the obstacle.

◆ WorldScale

Vector3 NavAI.Obstacle.WorldScale
get

Gets the world scale of the obstacle.

This is the transform.lossyScale multiplied by the obstacle's localScale.

◆ Zone

NavigationZone NavAI.Obstacle.Zone
getset

Gets the zone of the obstacle.

◆ ZoneAngle

float NavAI.Obstacle.ZoneAngle
get

Gets the degrees Y angle of the obstacle in it's zone local space.

◆ ZonePosition

Vector2 NavAI.Obstacle.ZonePosition
get

Gets the position of the obstacle in it's zone local space (X, Z).

This is the equivalent of Zone.WorldToLocalPoint(transform.position).

◆ ZoneRadius

float NavAI.Obstacle.ZoneRadius
get

Gets the radius of the obstacle in it's zone local space.

◆ ZoneScale

Vector2 NavAI.Obstacle.ZoneScale
get

Gets the scale of the obstacle in it's zone local space.

Since the obstacle collider is roughly 2D, there is no need to keep track of the sacle on the Y axis.

It would be mathematically correct for this scale to affect the obstacle collider scaling on the zone coordinate system, but that would cause distortion of the obstacle collider, which is not the intention. Using this scale on the obstacle local space simply makes the collider larger, without distorting it.

This field is only used by dynamic obstacles.