private void Move() { float t = m_t; UpdatePosition(t); float v = m_spline.GetVelocity(t).magnitude; v *= m_spline.CurveCount; if (m_t >= 1.0f) { m_t = (m_t - 1.0f) + (Time.deltaTime * Speed) / v; if (!m_spline.Loop && !IsLoop) { m_t = 1.0f; m_isCompleted = true; IsRunning = false; m_isRunning = false; //Completed.Invoke(); } if (IsLoop) { if (m_spline != Spline) { Restart(); } } } else { m_t += (Time.deltaTime * Speed) / v; } }
public static float GetLengthLG(this SplineBase spline) { float z = 0.5f, sum = 0.0f; int len = Tvalues.Length; for (int i = 0; i < len; i++) { float t = z * Tvalues[i] + z; sum += Cvalues[i] * spline.GetVelocity(t).magnitude; } return(z * sum); }
private void Move() { int curveIndex = m_spline.ToCurveIndex(m_t); if (m_curveIndex != curveIndex || m_t >= 1.0f) { CheckBranches(curveIndex); } float t = m_t; UpdatePosition(t); float v = m_spline.GetVelocity(t).magnitude; v *= m_spline.CurveCount; if (m_t >= 1.0f) { if (m_spline.NextSpline != null) { int nextControlPointIndex = m_spline.NextControlPointIndex; m_curveIndex = nextControlPointIndex / 3; m_spline = m_spline.NextSpline; if (m_spline.NextControlPointIndex > 0) { m_t = ((float)m_curveIndex) / m_spline.CurveCount; m_curveIndex++; } else { m_t = ((float)m_curveIndex) / m_spline.CurveCount; } Debug.Log("Next Spline " + m_curveIndex); CheckBranches(m_curveIndex); } else { m_t = (m_t - 1.0f) + (Time.deltaTime * Speed) / v; if (!m_spline.Loop && !IsLoop) { m_t = 1.0f; m_isCompleted = true; IsRunning = false; m_isRunning = false; Completed.Invoke(); } if (IsLoop) { if (m_spline != Spline) { Restart(); } } } } else { m_t += (Time.deltaTime * Speed) / v; } }
private float GetSpeed(int curve, float t) { return(m_spline.GetVelocity(t, curve).magnitude); }