private void calculatePath() { path.Clear(); currPathIndex = 0; lerpVal = 0; int cond = generateLoop ? localPoints.Count : localPoints.Count - 3; for (int i = 0; i < cond; i++) { Vector2[] splinePoints = new Vector2[4]; for (int k = 0; k < 4; k++) { int j = (i + k) % localPoints.Count; splinePoints[k] = localPoints[j]; } CatmullRomSpline crs = new CatmullRomSpline(splinePoints[0], splinePoints[1], splinePoints[2], splinePoints[3]); crs.InitNonuniformCatmullRom(); for (float j = 0; j < 1.0f;) { Vector3 p = crs.Eval(j); Vector3 deriv = crs.Deriv(j); j += step / deriv.magnitude; path.Add(p); } Vector3 diff = path[path.Count - 1] - splinePoints[2]; if (diff.magnitude >= cleanUpDist) { path.RemoveAt(path.Count - 1); } if (i == cond - 1) { path.Add(splinePoints[2]); } } }