• 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();
         }
     }
Show more comments
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Object rotation with angle constraints 0 Answers

Why my angle lerp code take only 30% time to finish? 0 Answers

How do multiple objects in sequence from a queue? 0 Answers

Best way (performance wise) to move multiple objects in certain time 0 Answers

Object lerping forwards a set distance every 3 seconds. 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