N - Type of nodeV - Type of vector, either 2D or 3D, implementing the Vector interfacepublic class PathSmoother<N,V extends com.badlogic.gdx.math.Vector<V>>
extends java.lang.Object
PathSmoother takes a SmoothableGraphPath and transforms it by linking directly the nodes that are in line of
sight. The smoothed path contains at most as many nodes as the original path. Also, the nodes in the smoothed path are unlikely
to have any connections between them (if they were connected in the graph, the pathfinder would have found the smoothed route
directly, unless their connections had dramatically large costs).
Some world representations are more prone to rough paths than others. Fore example, tile-based graphs tend to be highly erratic. The final appearance also depends on how characters act on the path. If they are using some kind of path following steering behavior, then the path will be gently smoothed by the steering. It is worth testing your game before assuming the path will need smoothing.
For some games, path smoothing is essential to get the AI looking smart. The path smoothing algorithm is rather simple but involves raycast and can be somewhat time-consuming.
The algorithm assumes that there is a clear route between any two adjacent nodes in the given path. Although this algorithm produces a smooth path, it doesn't search all possible smoothed paths to find the best one, but the final result is usually much more satisfactory than the original path.
| Constructor and Description |
|---|
PathSmoother(RaycastCollisionDetector<V> raycastCollisionDetector)
Creates a
PathSmoother using the given RaycastCollisionDetector |
| Modifier and Type | Method and Description |
|---|---|
boolean |
smoothPath(PathSmootherRequest<N,V> request,
long timeToRun)
Smoothes in place the path specified by the given request, possibly over multiple consecutive frames.
|
int |
smoothPath(SmoothableGraphPath<N,V> path)
Smoothes the given path in place.
|
public PathSmoother(RaycastCollisionDetector<V> raycastCollisionDetector)
PathSmoother using the given RaycastCollisionDetectorraycastCollisionDetector - the raycast collision detectorpublic int smoothPath(SmoothableGraphPath<N,V> path)
path - the path to smoothpublic boolean smoothPath(PathSmootherRequest<N,V> request, long timeToRun)
request - the path smoothing requesttimeToRun - the time in nanoseconds that this call can use on the current frametrue if this operation has completed; false if more time is needed to complete.