N- Type of node
V- Type of vector, either 2D or 3D, implementing the
public class PathSmoother<N,V extends com.badlogic.gdx.math.Vector<V>> extends java.lang.Object
SmoothableGraphPathand 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|
|Modifier and Type||Method and Description|
Smoothes in place the path specified by the given request, possibly over multiple consecutive frames.
Smoothes the given path in place.
public int smoothPath(SmoothableGraphPath<N,V> path)
path- the path to smooth
public boolean smoothPath(PathSmootherRequest<N,V> request, long timeToRun)
request- the path smoothing request
timeToRun- the time in nanoseconds that this call can use on the current frame
trueif this operation has completed;
falseif more time is needed to complete.