• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

What are the benefits of 1 unit per meter? 2 Answers

What precision do I have to use for shader parameters? 0 Answers

Lerp Doesn't Work On Mobile 1 Answer

MonoDevelop Xamarin Source Analysis warning about float comparison? 2 Answers

fromtorotation inacurate Help fixing? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges