Very simple implementation of path smoothing algorithm.
private void
GenerateSmoothedPaths()
{
smoothedPaths.Clear();
smoothedPaths.Add(paths[0].transform.position);
int index = 1;
while(index <
paths.Length-1)
{
Vector3
fromPos = smoothedPaths[smoothedPaths.Count - 1];
Vector3
toPos = paths[index].transform.position;
Ray ray =
new Ray(fromPos, (toPos - fromPos).normalized);
RaycastHit hitInfo;
if ( Physics.Raycast(ray,
out hitInfo, Vector3.Distance(fromPos, toPos)) )
{
smoothedPaths.Add(paths[index-1].transform.position);
}
index++;
}
smoothedPaths.Add(paths[paths.Length-1].transform.position);
}
|
No comments:
Post a Comment