Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by rjth · Nov 03, 2016 at 06:25 PM · coroutinelerpgraph

Lerping Vectorisity spline

I am drawing a graph using Vectorisity. Every time I get a new measurement I would like to interpolate between the two states of the graph, the old data and the new. I am doing this using a coroutine, however it isn't working yet.

     IEnumerator DrawGraph(Vector3[] coordinates, float duration)
     {
         float startTime = Time.time;
         float endTime = startTime + duration;
 
         while (Time.time <= endTime)
         {
             float t = (Time.time - startTime) / duration;
 
             for(int i = 0; i < coordinates.Length; i++)
             {
                 coordinates[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
             }
             GraphSpline.MakeSpline(coordinates, coordinates.Length, false);
             GraphSpline.Draw3D();
 
             yield return null;
         }
     }

Could you suggest me any fixes?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TreyH · Nov 03, 2016 at 06:56 PM 1
Share

Well, what isn't working?

avatar image rjth TreyH · Nov 03, 2016 at 08:19 PM 0
Share

It is not interpolating between the coordinates, it just snaps from one state to another.

avatar image TreyH · Nov 03, 2016 at 11:36 PM 1
Share

Try replacing your yield return with:

 yield return new WaitForEndOfFrame ();
avatar image rjth TreyH · Nov 04, 2016 at 12:44 PM 0
Share

It is still not working unfortunately. Here is a little bit larger snippet of my current code:

     void DrawSpline(List<Vector3> coordinates)
     {
         Vector3[] coordinateArray = coordinates.ToArray();
         if(previousCoordinateArray == null)
         {
             GraphSpline = new VectorLine("GraphSpline", new List<Vector3>(coordinates.Count + 1), GraphTexture, GraphLineWidth, LineType.Continuous);
             GraphSpline.joins = Joins.Weld;
             GraphSpline.continuousTexture = true;
             GraphSpline.$$anonymous$$akeSpline(coordinateArray, coordinateArray.Length, false);
             GraphSpline.Draw3D();
         }
         else
         {
             //CreateStaticGraph(coordinateArray);
             StartCoroutine(CreateGraph(coordinateArray, 5f));
         }
         previousCoordinateArray = coordinateArray;
     }
 
     IEnumerator CreateGraph(Vector3[] coordinates, float duration)
     {
         float startTime = Time.time;
         float endTime = startTime + duration;
 
         while (Time.time <= endTime)
         {
             float t = (Time.time - startTime) / duration;
 
             for(int i = 0; i < coordinates.Length; i++)
             {
                 coordinates[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
             }
 
             GraphSpline.$$anonymous$$akeSpline(coordinates, coordinates.Length, false);
             GraphSpline.Draw3D();
 
             yield return new WaitForEndOfFrame();
         }
     }
avatar image TreyH rjth · Nov 04, 2016 at 01:31 PM 0
Share

Looks like you might've been assigning the coordinates in reverse order.

What does it do if you try this:

 IEnumerator CreateGraph(Vector3[] coordinates, float duration)
 {
     float startTime = Time.time;
     float currentTime = Time.time;
     float endTime = currentTime + duration;
 
     while (currentTime <= endTime)
     {
         float t = (currentTime - startTime) / duration;
 
         for(int i = 0; i < coordinates.Length; i++)
         {
             previousCoordinateArray[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
         }
 
         GraphSpline.$$anonymous$$akeSpline(previousCoordinateArray, previousCoordinateArray.Length, false);
         GraphSpline.Draw3D();
 
         yield return new WaitForEndOfFrame();
 
         // Resample the time after that yield finishes
         currentTime = Time.time;
     }
 
     // Snap these in case we have a ti$$anonymous$$g issue
     GraphSpline.$$anonymous$$akeSpline(coordinates, coordinates.Length, false);
     GraphSpline.Draw3D();
 }
avatar image rjth TreyH · Nov 04, 2016 at 02:23 PM 0
Share

I have made it work, I needed to store the vectors from the lerping in a temporary array.

     IEnumerator CreateGraph(Vector3[] coordinates, float duration)
     {
         float startTime = Time.time;
         float endTime = startTime + duration;
 
         while (Time.time <= endTime)
         {
             float t = (Time.time - startTime) / duration;
 
             for(int i = 0; i < coordinates.Length; i++)
             {
                 tempCoordinateArray[i] = Vector3.Lerp(previousCoordinateArray[i], coordinates[i], t);
             }
 
             GraphSpline.$$anonymous$$akeSpline(tempCoordinateArray, coordinates.Length, false);
             GraphSpline.Draw3D();
 
             tempCoordinateArray = previousCoordinateArray;
 
             yield return new WaitForEndOfFrame();
         }
     }

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

81 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

MoveTowards and Lerp not working 1 Answer

Creating points for robot (End Effector) to go through them 0 Answers

Weapon does't meet the target position when using IK 1 Answer

Lerp between two int vaules smoothly 4 Answers

Control lerps with if-statemnts in Update or with Coroutines? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges