Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 ratchetunity · May 14, 2019 at 10:14 AM · transform.positionlinerenderermove an objectmovinggameobjectline drawing

Recalculate linerenderer when moving gameobjects

Hi!

I'm creating spheres that are linked between then using a linerenderer. What I need, and I don't know how to do it, is to "update" the linerenderer just when one of the spheres moves. This is my code:

 [SerializeField] GameObject[] spheres;
 [SerializeField] GameObject link;
 private LineRenderer lineRenderer;

 private void Awake () {
     lineRenderer = link.GetComponent<LineRenderer>();
     lineRenderer.positionCount = 2;
 }
 
 private void Start () {
     CreateShape();
 }

 private void CreateShape ()
 {
     for (int i = 0; i < spheres.Length; i++)
     {
         for (int j = i + 1; j < spheres.Length; j++)
         {
             link.name = spheres[j].transform.name;
             lineRenderer.SetPosition(0, spheres[i].transform.position);
             lineRenderer.SetPosition(1, spheres[j].transform.position);
             Instantiate(link, Vector3.zero, Quaternion.identity, spheres[i].transform);
         }
     }
 }
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
0

Answer by tormentoarmagedoom · May 14, 2019 at 10:25 AM

Hello.

Where is the problem? If you get to correctly create the line, you only need to update the points.

Every time a sphere moves, you need to use lineRenderer.SetPosition again with the neew positions. As you do it refering directly the sphere , just do this again in update, or every time a sphere is moving

          lineRenderer.SetPosition(0, spheres[i].transform.position);
          lineRenderer.SetPosition(1, spheres[j].transform.position);

Bye!

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 ratchetunity · May 14, 2019 at 10:37 AM 0
Share

Hi @tormentoarmagedoom ! Thanks for your answer, but I've already tried that and it doesn't work (I think because I'm instantiating the linerenderer)

avatar image tormentoarmagedoom ratchetunity · May 15, 2019 at 11:37 AM 0
Share

are you sure you are trying to change the position to the corect linerenderer? i mean, $$anonymous$$eybe you continue instantiating things and linrenderer variable is now another thing or something like that...

And maybe is stupid question, and i dont know exactly what effect you pretend to achieve, but, did you tried with trail renderer?

And as last chance, watch this links:

https://forum.unity.com/threads/change-start-position-of-line-renderer.448059/

Consider using SetPositions (with S)

https://docs.unity3d.com/ScriptReference/LineRenderer.SetPositions.html

I had the same problem some years ago, but i rememebr i finally get it and was not difficult. I rememebr the fisrt things i tried didnt work, but finnally get it (without strange thigs)

Good luck! :D

Bye!

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

107 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

Related Questions

How should I do to draw lines like this? 0 Answers

How to create a Mesh made up of lines, not triangles 2 Answers

Convert Line Render to 3d Mesh with Collider 0 Answers

How to make a ladder script for unitiy's FPS controller? 1 Answer

How to draw a line with arrow mark in unity? 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