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 /
avatar image
0
Question by Pulsar12 · Mar 22, 2019 at 04:53 AM · positionlerplinerenderer

LineRenderer (strange bug)

Hello, I have a pretty weird problem with the LineRenderer component: I want to join each WayPoint (capsule) of my scene with LineRenderer in a progressive way. I managed to do it with the code below but each time it touches a WayPoint (capsule), a line is created to the point 0,0,0 for 1 frame before disappearing. I do not understand ... my code is correct and does not mention doing that.alt text

alt text

my assumption is that it comes when I increment its size '' lineRenderer.positionCount ++ "which makes me create a time 0,0,0 before the position changes.

Do you have an idea to avoid this temporary line please? Here is my code that I commented the 5/6 lines of code concerned by the LineRenderer with '' // here '':

     LineRenderer lineRenderer;
     private int indexLine = 0;
     public float linearSpeed = 5;

     private void Start()
     {
         lineRenderer = gameObject.GetComponent<LineRenderer>();  //here
         lineRenderer.positionCount = 1;  //here
         lineRenderer.SetPosition(0, start.transform.position);  //here
         NavigateTo(start, end);
     }
     
     void Update()
     {
         if (currentPath != null && currentPath.Count > 0) 
         {
             if (moveTimeCurrent < moveTimeTotal)
             {
                 moveTimeCurrent += Time.deltaTime;
                 if (moveTimeCurrent > moveTimeTotal)
                     moveTimeCurrent = moveTimeTotal;
                 var pointALongLine = Vector3.Lerp (currentWaypointPosition, currentPath.Peek(), moveTimeCurrent / moveTimeTotal);  //here
                 lineRenderer.SetPosition(indexLine, pointALongLine);  //here
             } else
             {
                 currentWaypointPosition = currentPath.Pop(); 
                 if (currentPath.Count == 0)
                     Stop ();
                 else
                 {
                     lineRenderer.positionCount++; //here
                     indexLine = indexLine + 1; //here
                     moveTimeCurrent = 0;
                     moveTimeTotal = (currentWaypointPosition - currentPath.Peek()).magnitude / linearSpeed;
                 }



ma-capture-01-1.gif (61.2 kB)
capture.png (31.7 kB)
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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Mar 22, 2019 at 06:39 AM

I'd say it comes from the fact that in the else part, you are adding a new entry in the array without setting any value to it. So it gets default.

You could try to add the value and set it as the current value so it won't show the full line for a frame again.

                  lineRenderer.positionCount++; //here
                  lineRenderer.SetPosition(lineRenderer.positionCount - 1, currentWaypointPosition);

This should add a new entry and set it as the last one.

Comment
Add comment · Show 2 · 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 Pulsar12 · Mar 22, 2019 at 06:48 AM 0
Share

Oh...I did not think about it! Thank you very much fafase!

PS: I specify for those with the problem that this is '' lineRenderer.SetPosition (lineRenderer.positionCount-1, currentWaypointPosition); '' because length doesn't exist for lineRenderer.

avatar image fafase · Mar 22, 2019 at 06:56 AM 1
Share

Yep, I'll edit the answer, I did that one with no editor.

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

124 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

Related Questions

Add specific movement on double click 1 Answer

Mathf.Lerp not working 2 Answers

Move object while rotating another one 1 Answer

Setting the position of linerenderer 1 Answer

How do I translate around a circle? 3 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