A* Pathfinding Project  4.1.7
The A* Pathfinding Project for Unity 3D
RaycastModifier Class Reference

Simplifies a path using raycasting. More...

Detailed Description

Simplifies a path using raycasting.

This modifier will try to remove as many nodes as possible from the path using raycasting (linecasting) to validate the node removal. You can use either graph raycasting or Physics.Raycast. When using graph raycasting, the graph will be traversed and checked for obstacles. When physics raycasting is used, the Unity physics system will be asked if there are any colliders which intersect the line that is currently being checked.

Public Member Functions

override void Apply (Path p)
 Called for each path that the Seeker calculates after the calculation has finished. More...
 
bool ValidateLine (GraphNode n1, GraphNode n2, Vector3 v1, Vector3 v2)
 Check if a straight path between v1 and v2 is valid. More...
 
- Public Member Functions inherited from MonoModifier
virtual void PreProcess (Path path)
 

Public Attributes

int iterations = 2
 How many iterations to try to simplify the path. More...
 
LayerMask mask = -1
 Layer mask used for physics raycasting. More...
 
Vector3 raycastOffset = Vector3.zero
 Offset from the original positions to perform the raycast. More...
 
bool subdivideEveryIter
 Subdivides the path every iteration to be able to find shorter paths. More...
 
bool thickRaycast
 Checks around the line between two points, not just the exact line. More...
 
float thickRaycastRadius
 Distance from the ray which will be checked for colliders. More...
 
bool use2DPhysics
 Check for intersections with 2D colliders instead of 3D colliders. More...
 
bool useGraphRaycasting
 Use raycasting on the graphs. More...
 
bool useRaycasting = true
 Use Physics.Raycast to simplify the path. More...
 
- Public Attributes inherited from MonoModifier
Seeker seeker
 

Properties

override int Order [get]
 
- Properties inherited from MonoModifier
abstract int Order [get]
 Modifiers will be executed from lower order to higher order. More...
 
- Properties inherited from IPathModifier
int Order [get]
 

Static Private Member Functions

static void Subdivide (List< Vector3 > points)
 Divides each segment in the list into 3 segments. More...
 

Additional Inherited Members

- Protected Member Functions inherited from MonoModifier
virtual void OnDisable ()
 
virtual void OnEnable ()
 Alerts the Seeker that this modifier exists. More...
 
- Protected Member Functions inherited from VersionedMonoBehaviour
virtual void Awake ()
 
virtual int OnUpgradeSerializedData (int version, bool unityThread)
 Handle serialization backwards compatibility. More...
 

Member Function Documentation

◆ Apply()

override void Apply ( Path  path)
virtual

Called for each path that the Seeker calculates after the calculation has finished.

Implements MonoModifier.

◆ Subdivide()

static void Subdivide ( List< Vector3 >  points)
staticprivate

Divides each segment in the list into 3 segments.

◆ ValidateLine()

bool ValidateLine ( GraphNode  n1,
GraphNode  n2,
Vector3  v1,
Vector3  v2 
)

Check if a straight path between v1 and v2 is valid.

Member Data Documentation

◆ iterations

int iterations = 2

How many iterations to try to simplify the path.

If the path is changed in one iteration, the next iteration may find more simplification oppourtunities

◆ mask

LayerMask mask = -1

Layer mask used for physics raycasting.

◆ raycastOffset

Vector3 raycastOffset = Vector3.zero

Offset from the original positions to perform the raycast.

Can be useful to avoid the raycast intersecting the ground or similar things you do not want to it intersect

◆ subdivideEveryIter

bool subdivideEveryIter

Subdivides the path every iteration to be able to find shorter paths.

◆ thickRaycast

bool thickRaycast

Checks around the line between two points, not just the exact line.

Make sure the ground is either too far below or is not inside the mask since otherwise the raycast might always hit the ground

◆ thickRaycastRadius

float thickRaycastRadius

Distance from the ray which will be checked for colliders.

◆ use2DPhysics

bool use2DPhysics

Check for intersections with 2D colliders instead of 3D colliders.

Useful for 2D games.

◆ useGraphRaycasting

bool useGraphRaycasting

Use raycasting on the graphs.

Only currently works with GridGraph and NavmeshGraph and RecastGraph.

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

◆ useRaycasting

bool useRaycasting = true

Use Physics.Raycast to simplify the path.

Property Documentation

◆ Order

override int Order
get

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