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 /
This question was closed Apr 25, 2018 at 10:44 AM by tormentoarmagedoom for the following reason:

The question is answered, right answer was accepted

avatar image
-1
Question by Earthworms · Apr 24, 2018 at 01:56 PM · arraylerpvector2polygontriangulation

How to use Vector2.Lerp in two arrays

My question is mostly in the title. I’m stuck because I want to lerp the whole Vector2 a with the entire Vector2 b. Sorry for my english, hope you guys will understand !

 Vector2[] vertices2D1 = new Vector2[] {    
         new Vector2(0,0),
         new Vector2(54.7f,53.9f),
         new Vector2(77.3f,141.8f),
         new Vector2(77.3f,327.6f),
         new Vector2(54.7f,428.1f),
         new Vector2(0,500),
     };

For example I can change the first element of my first array with vertices2D [0].x = 10f; vertices2D [0].y = 15f; but it becomes instantly (no transition), how use this with void update .And i can't use lerp with this syntax for example Vector2.Lerp(vertices2D [0].x, "here my new vector" ,0.3f); Thank you

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Hellium · Apr 24, 2018 at 03:00 PM

I don't really understand your problem....

For example, if you want an object to go smoothly from 1st vector, to 2nd one, and so on, you can do the following:

 public float speed = 1;

 Vector2[] vertices2D1 = new Vector2[] {    
      new Vector2(0,0),
      new Vector2(54.7f,53.9f),
      new Vector2(77.3f,141.8f),
      new Vector2(77.3f,327.6f),
      new Vector2(54.7f,428.1f),
      new Vector2(0,500),
  };
  int currentIndex = 0 ;
  float progress = 0 ;
  Vector3 startPosition ;
  Vector3 endPosition ;

 void Start()
 {
     startPosition = transform.position ;
     endPosition = vertices2D1[currentIndex];
 }

 void Update()
 {
     progress += Time.deltaTime * speed ;
     transform.position = Vector2.Lerp( startPosition, endPosition, progress ) ;
     if( progress >= 1 )
     {
         progress = 0 ;
         currentIndex = ( currentIndex + 1 ) % vertices2D1.Length ;
         startPosition = endPosition ;
         endPosition = vertices2D1[currentIndex] ;
     }
 }



If you want to smoothly change the 1st vector of the array:

 public float speed = 1;

 Vector2[] vertices2D1 = new Vector2[] {    
      new Vector2(0,0),
      new Vector2(54.7f,53.9f),
      new Vector2(77.3f,141.8f),
      new Vector2(77.3f,327.6f),
      new Vector2(54.7f,428.1f),
      new Vector2(0,500),
  };
  float progress = 0 ;

 void Update()
 {
     progress += Time.deltaTime * speed ;
     vertices2D1[0] = Vector2.Lerp( vertices2D1[0], <your_target_vector_here>, progress ) ;
 }
Comment
Add comment · Show 1 · Share
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 Earthworms · Apr 25, 2018 at 07:08 AM -1
Share

Oh, thank you ! Yes the second answer is good ;) i have two array the first :

 Vector2[] vertices2D1 = new Vector2[] {    
       new Vector2(0,0),
       new Vector2(54.7f,53.9f),
       new Vector2(77.3f,141.8f),
       new Vector2(77.3f,327.6f),
       new Vector2(54.7f,428.1f),
       new Vector2(0,500),
   };

and the second :

 Vector2[] vertices2D2 = new Vector2[] {    
       new Vector2(20,10),
       new Vector2(50f,8f),
       new Vector2(6f,10.8f),
       new Vector2(3f,300.6f),
       new Vector2(50.7f,418.1f),
       new Vector2(0,20),
   };

And i want to change all the vector in vertices2D1 array with all the vector in vertices 2D2 array (smoothly)

Follow this Question

Answers Answers and Comments

148 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 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

Lerp a vector2?,Lerp a Vector2? 0 Answers

Vector2.lerp dashing problem 0 Answers

Question about Array indexing 0 Answers

Help with Vector2.Lerp 2 Answers

Lerping at a constant rate? 2 Answers


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