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 Pezzl · Aug 08, 2017 at 06:10 PM · precisionlerping

Lerping multiple gameobjects precisely

For a project I need to continously lerp bars from left to right.

Each bar has a script on it, that lerps it to the right. When the bar hits the right border, it gets set to left border and start again to lerp from left to the right. The lerping works fine.

 void FixedUpdate()
     {
         if (BarSetting.Instance.Running)
         {
             //bar has reached the next position
             if (Vector3.Distance(transform.position, nextPosition) <= 0)
             {
                 //when the bar has reached set the next position
                 startPosition = movementType.getFirst();
                 transform.position = startPosition;
                 nextPosition = movementType.getLast();
 
                 //reset the timer for the lerp transition
                 float distanceBetweenStartAndNext = Vector3.Distance(startPosition, nextPosition);
 
                 timeToReachNextPosition = Utilities.CircumferenceInUnits(BarSetting.Instance.Speed) * distanceBetweenStartAndNext;
                 timePassed = 0;
             }
             else
             {
                 //move the bar closer to the next position
                 timePassed += Time.deltaTime / timeToReachNextPosition;
                 this.transform.position = Vector3.Lerp(startPosition, nextPosition, timePassed);
             }
         }
     }

The problem is that the space between the bars doesn't stay exact the same. With just a few bars it works fine, but I need to lerp like 30 bars and there the space varies a lot.

I dont think, that the problem lies with the lerping itself. It seems, that Unity has problems with handling multiple lerping exactly.

Startposition of all bars: startposition of all bars

How they end up after a few rounds how they end up after a few rounds

Has somebody an idea for a fix or an alternative solution?

Thanks in advance.

xqxly.jpg (109.7 kB)
qkfyw.jpg (92.4 kB)
Comment
Add comment · Show 1
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 Pezzl · Aug 14, 2017 at 10:08 AM 0
Share

If everyone is interested in my current solution: The problem with my scene was, that i lerped each bar individual, which isnt very precise. So I've parented half the bars on one empty gameobejct and the other half on another empty gameobject. The script, which was lerping the bars, got modified to lerp the gameobjects parenting the bars. With this modification the bars keep exact the same space inbetween.

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

110 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

Related Questions

Script's if statement dealing with time/float modulus remainder zero does not work properly when done with Application.LoadLevel() from other scene? 1 Answer

Lerp Problem 1 Answer

Camera Smoothing from pos A - pos B in Unity 2D 0 Answers

Iam developing a healthcare app where all units are in mm.. STL and Dicom..Precision is paramount 0 Answers

How do I make tiles that light up when gameobject touches them? 0 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