A* Pathfinding Project  4.3.5
The A* Pathfinding Project for Unity 3D
GraphCollision Class Reference

Handles collision checking for graphs. More...

Detailed Description

Handles collision checking for graphs.

Mostly used by grid based graphs

Public Member Functions

bool Check (Vector3 position)
 Returns if the position is obstructed. More...
 
Vector3 CheckHeight (Vector3 position)
 Returns the position with the correct height. More...
 
Vector3 CheckHeight (Vector3 position, out RaycastHit hit, out bool walkable)
 Returns the position with the correct height. More...
 
RaycastHit [] CheckHeightAll (Vector3 position, out int numHits)
 Returns all hits when checking height for position. More...
 
void DeserializeSettingsCompatibility (GraphSerializationContext ctx)
 
void Initialize (GraphTransform transform, float scale)
 Sets up several variables using the specified matrix and scale. More...
 
void JobCollisionRay (NativeArray< Vector3 > nodePositions, NativeArray< bool > collisionCheckResult, Vector3 up, Allocator allocationMethod, JobDependencyTracker dependencyTracker)
 Returns if the position is obstructed for all nodes using the Ray collision checking method. More...
 

Public Attributes

bool collisionCheck = true
 Toggle collision check. More...
 
float collisionOffset
 Height above the ground that collision checks should be done. More...
 
float diameter = 1F
 Diameter of capsule or sphere when checking for collision. More...
 
float fromHeight = 100
 The height to check from when checking height ('ray length' in the inspector). More...
 
float height = 2F
 Height of capsule or length of ray when checking for collision. More...
 
bool heightCheck = true
 Toggle height check. More...
 
LayerMask heightMask = -1
 Layers to be included in the height check. More...
 
LayerMask mask
 Layers to be treated as obstacles. More...
 
const float RaycastErrorMargin = 0.005F
 Offset to apply after each raycast to make sure we don't hit the same point again in CheckHeightAll. More...
 
RayDirection rayDirection = RayDirection.Both
 Direction of the ray when checking for collision. More...
 
bool thickRaycast
 Toggles thick raycast. More...
 
float thickRaycastDiameter = 1
 Diameter of the thick raycast in nodes. More...
 
ColliderType type = ColliderType.Capsule
 Collision shape to use. More...
 
bool unwalkableWhenNoGround = true
 Make nodes unwalkable when no ground was found with the height raycast. More...
 
Vector3 up
 Direction to use as UP. More...
 
bool use2D
 Use Unity 2D Physics API. More...
 

Private Attributes

float finalRadius
 diameter * scale * 0.5. More...
 
float finalRaycastRadius
 thickRaycastDiameter * scale * 0.5. More...
 
RaycastHit [] hitBuffer = new RaycastHit[8]
 Internal buffer used by CheckHeightAll. More...
 
Vector3 upheight
 up * height. More...
 

Member Function Documentation

◆ Check()

bool Check ( Vector3  position)

Returns if the position is obstructed.

If collisionCheck is false, this will always return true.

◆ CheckHeight() [1/2]

Vector3 CheckHeight ( Vector3  position)

Returns the position with the correct height.

If heightCheck is false, this will return position.

◆ CheckHeight() [2/2]

Vector3 CheckHeight ( Vector3  position,
out RaycastHit  hit,
out bool  walkable 
)

Returns the position with the correct height.

If heightCheck is false, this will return position.
walkable will be set to false if nothing was hit. The ray will check a tiny bit further than to the grids base to avoid floating point errors when the ground is exactly at the base of the grid

◆ CheckHeightAll()

RaycastHit [] CheckHeightAll ( Vector3  position,
out int  numHits 
)

Returns all hits when checking height for position.

Warning
Does not work well with thick raycast, will only return an object a single time
The returned array is ephermal. It will be invalidated when this method is called again. If you need persistent results you should copy it.

The returned array may be larger than the actual number of hits, the numHits out parameter indicates how many hits there actually were.

◆ DeserializeSettingsCompatibility()

void DeserializeSettingsCompatibility ( GraphSerializationContext  ctx)

◆ Initialize()

void Initialize ( GraphTransform  transform,
float  scale 
)

Sets up several variables using the specified matrix and scale.

See also
GraphCollision.up
GraphCollision.upheight
GraphCollision.finalRadius
GraphCollision.finalRaycastRadius

◆ JobCollisionRay()

void JobCollisionRay ( NativeArray< Vector3 >  nodePositions,
NativeArray< bool >  collisionCheckResult,
Vector3  up,
Allocator  allocationMethod,
JobDependencyTracker  dependencyTracker 
)

Returns if the position is obstructed for all nodes using the Ray collision checking method.

collisionCheckResult[i] = true if there were no obstructions, false otherwise

Member Data Documentation

◆ collisionCheck

bool collisionCheck = true

Toggle collision check.

◆ collisionOffset

float collisionOffset

Height above the ground that collision checks should be done.

For example, if the ground was found at y=0, collisionOffset = 2 type = Capsule and height = 3 then the physics system will be queried to see if there are any colliders in a capsule for which the bottom sphere that is made up of is centered at y=2 and the top sphere has its center at y=2+3=5.

If type = Sphere then the sphere's center would be at y=2 in this case.

◆ diameter

float diameter = 1F

Diameter of capsule or sphere when checking for collision.

When checking for collisions the system will check if any colliders overlap a specific shape at the node's position. The shape is determined by the type field.

A diameter of 1 means that the shape has a diameter equal to the node's width, or in other words it is equal to nodeSize .

If type is set to Ray, this does not affect anything.

◆ finalRadius

float finalRadius
private

diameter * scale * 0.5.

Where scale usually is nodeSize

See also
Initialize

◆ finalRaycastRadius

float finalRaycastRadius
private

thickRaycastDiameter * scale * 0.5.

Where scale usually is nodeSize

See also
Initialize

◆ fromHeight

float fromHeight = 100

The height to check from when checking height ('ray length' in the inspector).

As the image below visualizes, different ray lengths can make the ray hit different things. The distance is measured up from the graph plane.

◆ height

float height = 2F

Height of capsule or length of ray when checking for collision.

If type is set to Sphere, this does not affect anything.

◆ heightCheck

bool heightCheck = true

Toggle height check.

If false, the grid will be flat

◆ heightMask

LayerMask heightMask = -1

Layers to be included in the height check.

◆ hitBuffer

RaycastHit [] hitBuffer = new RaycastHit[8]
private

Internal buffer used by CheckHeightAll.

◆ mask

LayerMask mask

Layers to be treated as obstacles.

◆ RaycastErrorMargin

const float RaycastErrorMargin = 0.005F

Offset to apply after each raycast to make sure we don't hit the same point again in CheckHeightAll.

◆ rayDirection

Direction of the ray when checking for collision.

If type is not Ray, this does not affect anything

Deprecated:
Only the Both mode is supported now.

◆ thickRaycast

bool thickRaycast

◆ thickRaycastDiameter

float thickRaycastDiameter = 1

Diameter of the thick raycast in nodes.

1 equals nodeSize

◆ type

Collision shape to use.

See also
Pathfinding.ColliderType

◆ unwalkableWhenNoGround

bool unwalkableWhenNoGround = true

Make nodes unwalkable when no ground was found with the height raycast.

If height raycast is turned off, this doesn't affect anything.

◆ up

Vector3 up

Direction to use as UP.

See also
Initialize

◆ upheight

Vector3 upheight
private

up * height.

See also
Initialize

◆ use2D

bool use2D

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