CRSpline.Velocity C# (CSharp) Method

Velocity() public static method

public static Velocity ( Vector3 pts, float t ) : Vector3
pts Vector3
t float
return Vector3
    public static Vector3 Velocity(Vector3[] pts, float t)
    {
        int numSections = pts.Length - 3;
        int currPt = Mathf.Min(Mathf.FloorToInt(t * (float) numSections), numSections - 1);
        float u = t * (float) numSections - (float) currPt;

        Vector3 a = pts[currPt];
        Vector3 b = pts[currPt + 1];
        Vector3 c = pts[currPt + 2];
        Vector3 d = pts[currPt + 3];

        return 1.5f * (-a + 3f * b - 3f * c + d) * (u * u)
                + (2f * a -5f * b + 4f * c - d) * u
                + .5f * c - .5f * a;
    }

Usage Example

Example #1
0
 public static Vector3 Velocity(Path pts, float t, Easing.EaseType easeType = Easing.EaseType.linear)
 {
     t = Easing.ease(easeType, t);
     if (pts.Length == 0)
     {
         return(Vector3.zero);
     }
     else if (pts.Length == 1)
     {
         return(pts[0]);
     }
     else if (pts.Length == 2)
     {
         return(Vector3.Lerp(pts[0], pts[1], t));
     }
     else if (pts.Length == 3)
     {
         return(QuadBez.Velocity(pts[0], pts[2], pts[1], t));
     }
     else if (pts.Length == 4)
     {
         return(CubicBez.Velocity(pts[0], pts[3], pts[1], pts[2], t));
     }
     else
     {
         return(CRSpline.Velocity(Wrap(pts), t));
     }
 }
All Usage Examples Of CRSpline::Velocity