Search Unity

Bezier Solution [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Nov 12, 2016.

  1. emonikino

    emonikino

    Joined:
    Nov 29, 2017
    Posts:
    8
    Yes, that's what I mean by resetting them. Here's what you need to do to reproduce it in the demo scene:

    1) In the hierarchy, choose the face-shaped spline. Then in inspector, uncheck the "Loop".
    2) Then unfold the spline in the hierarchy to expose all its points. Then choose all its points and do the same thing: set the Z positions into 0. This will make all the points in one plane.
    3) Now, select the first point, and then set the "Preceding Control Point" and "Following Control Point" into (0,0,0) in the inspector window.
    4) Back to hierarchy, select "CubeConstantSpeed". Then set the "Travel Mode" into "Ping Pong". This step is not necessary but make things easier to see the problem later.
    5) Now start playing.

    I hope I describe the step correctly. Sorry for the late reply and thank you for your quick reply.
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    950
    Thank you for the detailed steps, I was able to reproduce the issue. However, I'm not sure how I should approach this problem. It is caused by this function:

    Code (CSharp):
    1. public Vector3 MoveAlongSpline( ref float normalizedT, float deltaMovement, int accuracy = 3 )
    2. {
    3.     // Credit: https://gamedev.stackexchange.com/a/27138
    4.  
    5.     float constant = deltaMovement / ( ( loop ? endPoints.Count : endPoints.Count - 1 ) * accuracy );
    6.     for( int i = 0; i < accuracy; i++ )
    7.         normalizedT += constant / GetTangent( normalizedT ).magnitude; // Problematic line
    8.  
    9.     return GetPoint( normalizedT );
    10. }
    GetTangent returns 0 if controls points are set to (0,0,0). Then normalizedT immediately becomes Infinity. I think I can force the control points to have a minimum magnitude of 0.1 which would resolve this issue. What do you think?
     
    emonikino likes this.
  3. emonikino

    emonikino

    Joined:
    Nov 29, 2017
    Posts:
    8
    I personally like the code as it because if I work in 3d, I can still have (0,0,0) control points. But I'm sure people out there will stumble on the same issue sooner or later

    Setting up minimum control point magnitude will solve this problem and I'm okay with that. However, If possible, I rather solve the issue by manipulating the "GetTangent( normalizedT ).magnitude" to avoid infinity. Because the infinity issue seems only affecting this "MoveAlongSpline" function. This will leave everything else intact.

    I don't know much about math and this Tangent stuff surely beyond my grasp. Sorry if I say something ridiculous.
     
  4. emonikino

    emonikino

    Joined:
    Nov 29, 2017
    Posts:
    8
    Or, you can simply put "yellow warning icon" on control point inspector about that specific issue. Just like what Unity does:

    Screen Shot 2019-07-07 at 07.25.07.png
     
  5. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    950
    These are really nice recommendations, thank you! I'll see what I can do.

    P.S. Updated the plugin on GitHub to show a warning message as you've suggested.
     
    Last edited: Jul 7, 2019
    emonikino likes this.
  6. emonikino

    emonikino

    Joined:
    Nov 29, 2017
    Posts:
    8
    You're very welcome. Your plugin is one of the best there is and I'm sure anybody is willing to help you to improve it.
     
    yasirkula likes this.