public static bool RemoveOverlap(this IRageSpline path, int index0, int index1, float snapRadius, bool debug) { if (index1 == 0) { index0 = path.GetPointCount() - 1; } if (Vector3.Distance(path.GetPositionWorldSpace(index0), path.GetPositionWorldSpace(index1)) <= snapRadius) { if (debug) { Debug.Log("overlap path pos = " + path.GetPositionWorldSpace(index0)); } path.SetNatural(index1, false); path.SetInControlPositionWorldSpace(index1, path.GetInControlPositionWorldSpace(index0)); path.RemovePoint(index0); // Then deletes the duplicate previous point return(true); } return(false); }
/// <summary> Special case for start-end points, where the out tangent must be copied instead of the in tangent </summary> public static bool MergeStartEndPoints(this IRageSpline rageSpline, bool debug) { if (rageSpline.GetPointCount() <= 2) { return(false); } var lastPointIdx = rageSpline.GetPointCount() - 1; var lastPointPos = rageSpline.GetPositionWorldSpace(lastPointIdx); var firstPointPos = rageSpline.GetPositionWorldSpace(0); if (Vector3.Distance(firstPointPos, lastPointPos) < 0.0001f) { if (debug) { Debug.Log("\t Removing endpoint overlap "); } rageSpline.SetInControlPositionWorldSpace(0, rageSpline.GetInControlPositionWorldSpace(lastPointIdx)); rageSpline.RemovePoint(lastPointIdx); // Then deletes the last point return(true); } return(false); }
// Update is called once per frame void FixedUpdate() { for (int i = 0; i < rageSpline.GetPointCount() - 1; i++) { if (rageSpline.GetPositionWorldSpace(i + 1).x < cam.transform.position.x - (1024f / 768f) * cam.orthographicSize * 2f) { rageSpline.RemovePoint(i - 1); float x = (rageSpline.GetPositionWorldSpace(rageSpline.GetPointCount() - 1).x + pointGapWidth); rageSpline.AddPointWorldSpace(rageSpline.GetPointCount(), GetNewLandscapePoint(x), transform.right * pointGapWidth * 0.33f); transform.position += new Vector3(pointGapWidth, 0f, 0f); for (int a = 0; a < rageSpline.GetPointCount(); a++) { rageSpline.SetPoint(a, rageSpline.GetPosition(a) + new Vector3(-pointGapWidth, 0f, 0f)); } rageSpline.RefreshMesh(); } } curSteepness = steepness + transform.position.x * 0.0001f; maxY = Mathf.Clamp(transform.position.x * 0.05f, 0f, 10f); }