Exemplo n.º 1
0
 public static Vector3 InterpConstantSpeed(Spline.Path pts, float t, Easing.EaseType easeType = Easing.EaseType.linear)
 {
     t = Easing.ease(easeType, t, 0f, 1f);
     if (pts.Length == 0)
     {
         return(Vector3.zero);
     }
     if (pts.Length == 1)
     {
         return(pts[0]);
     }
     if (pts.Length == 2)
     {
         return(Vector3.Lerp(pts[0], pts[1], t));
     }
     if (pts.Length == 3)
     {
         return(QuadBez.Interp(pts[0], pts[2], pts[1], t));
     }
     if (pts.Length == 4)
     {
         return(CubicBez.Interp(pts[0], pts[3], pts[1], pts[2], t));
     }
     return(CRSpline.InterpConstantSpeed(Spline.Wrap(pts), t));
 }
Exemplo n.º 2
0
    public static Vector3 MoveOnPath(Spline.Path pts, Vector3 currentPosition, ref float pathPosition, ref Quaternion rotation, float maxSpeed = 1f, float smoothnessFactor = 100f, Easing.EaseType easeType = Easing.EaseType.linear)
    {
        Vector3 vector = Spline.MoveOnPath(pts, currentPosition, ref pathPosition, maxSpeed, smoothnessFactor, easeType);

        rotation = ((!vector.Equals(currentPosition)) ? Quaternion.LookRotation(vector - currentPosition) : Quaternion.identity);
        return(vector);
    }
Exemplo n.º 3
0
    public static float PathLength(Spline.Path pts)
    {
        float   num  = 0f;
        Vector3 a    = Spline.Interp(pts, 0f, Easing.EaseType.linear);
        int     num2 = pts.Length * 20;

        for (int i = 1; i <= num2; i++)
        {
            float   t      = (float)i / (float)num2;
            Vector3 vector = Spline.Interp(pts, t, Easing.EaseType.linear);
            num += Vector3.Distance(a, vector);
            a    = vector;
        }
        return(num);
    }
Exemplo n.º 4
0
    public static Vector3 MoveOnPath(Spline.Path pts, Vector3 currentPosition, ref float pathPosition, float maxSpeed = 1f, float smoothnessFactor = 100f, Easing.EaseType easeType = Easing.EaseType.linear)
    {
        maxSpeed    *= Time.deltaTime;
        pathPosition = Mathf.Clamp01(pathPosition);
        Vector3 vector = Spline.Interp(pts, pathPosition, easeType);
        float   magnitude;

        while ((magnitude = (vector - currentPosition).magnitude) <= maxSpeed && pathPosition < 1f)
        {
            currentPosition = vector;
            maxSpeed       -= magnitude;
            pathPosition    = Mathf.Clamp01(pathPosition + 1f / smoothnessFactor);
            vector          = Spline.Interp(pts, pathPosition, easeType);
        }
        if (magnitude != 0f)
        {
            currentPosition = Vector3.MoveTowards(currentPosition, vector, maxSpeed);
        }
        return(currentPosition);
    }
Exemplo n.º 5
0
 public static Quaternion RotationBetween(Spline.Path pts, float t1, float t2, Easing.EaseType easeType = Easing.EaseType.linear)
 {
     return(Quaternion.LookRotation(Spline.Interp(pts, t2, easeType) - Spline.Interp(pts, t1, easeType)));
 }