Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

how to graph animationCurves in 3d space?

Discussion in 'Scripting' started by DerekMcKinley, May 6, 2019.

  1. DerekMcKinley

    DerekMcKinley

    Joined:
    Jun 24, 2014
    Posts:
    19
    Hello everyone, I have a function that can extract the coordinates (control points) of a animationCurve, but I was wondering if someone knows how I can graph the curves in 3d space, with draw gizmos or debug.drawLine I can make lines from one point to another but that does not generate the real curve that forms.

    Thank you for reading
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    The Handles class has a bunch of methods including DrawBezier that should be able to do this, but it's for drawing curves in the Scene view, and I don't think there is a way to apply these for drawing to the actual Game viewport.

    If you need them visible in the Game view, you will probably need to use a LineRenderer. If you have the Keyframes of the animation, you can use them to give instructions to the renderer. The Handles.MakeBezierPoints method might be able to get you an array of points using the bezier tangents, but you'll have to convert time-space tangents to world-space somehow, which will take some thinking.

    Does this sound like something you want to try?

    I also found this tutorial which will probably help a bit. It isn't for animation curves, though, so it isn't a solution on its own.
     
    DerekMcKinley likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,963
    What @Hyblademin said... just choose a number of samples to take across the range from min to max of your AnimationCurve and evaluate the curve at those points, and use the results to produce a line renderer with that many points.
     
    DerekMcKinley and lordofduct like this.
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    DerekMcKinley likes this.
  5. DerekMcKinley

    DerekMcKinley

    Joined:
    Jun 24, 2014
    Posts:
    19
    these solutions are great thank you very much
    @ Kurt-Dekker, I had not thought about that, it is so obviously
     
    Last edited: May 7, 2019
    Kurt-Dekker likes this.