Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 roroquessada · Oct 06, 2020 at 02:59 PM · linerendererrotatearound

Why my pivot point is only taken on the first LineRenderer?

Hi everyvone,

I would to create different LineRenderers with a rotation for everyone. Each new LineRenderer is rotated around a random pivot point taken on the previous LineRenderer.

alt text

For example, I create the first LineRenderer named l0, then, I create the next LineRenderer l1 by "cloning" l0 (with Instantiate command), taking a random Vector3 point vec on l0 and rotating l1 around vec. Then, I create l2 in the same way: cloning l1, taking a new random point vec on l1 and rotating l2 around vec. (see the above picture)

But the result is not what I'm expected. Each vec pivot point is taken on the first LineRenderer l0, therefore the next LineRenderers will not be close to their previous LineRenderer.

Do you know why? (Bonus question: two other spheres is created but I don't know why)

Result alt text

The code

 public class DungeonBuilder : MonoBehaviour
 {
 
     void Start()
     {
         //Start Room
         LineRenderer l0 = CreateStartRoom(); //Create a new LineRenderer in the space
         //Next rooms
         LineRenderer l1 = CreateRoom(l0, 0);
         LineRenderer l2 = CreateRoom(l1, 1);
     }
 
 
     private LineRenderer CreateRoom(LineRenderer old, int i)
     {
 
         //Choose a color
         var c = Color.white;
         if (i == 0) c = Color.red;
         if (i == 1) c = Color.blue;
         if (i == 2) c = Color.green;
         if (i == 3) c = Color.black;
 
         //Creation of the LineRenderer
         LineRenderer l = Instantiate(old);
         l.material = new Material(Shader.Find("Sprites/Default"));
         l.startWidth = 0.01f;
         l.endWidth = 0.01f;
         l.startColor = c;
         l.endColor = l.startColor;
         l.useWorldSpace = false; //For using the Transform component of LineRenderer
 
         //Get a random vertice/point of the LineRenderer
         Vector3 vec = old.GetPosition(Random.Range(0, old.positionCount));
 
         //Rotation
         l.gameObject.transform.RotateAround(vec, Vector3.up, 180);
 
         //Just a visual indication to see the pivot point
         GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         sphere.GetComponent<MeshRenderer>().material.SetColor("_Color", c);
         sphere.transform.localScale = new Vector3(-0.5f, -0.5f, -0.5f);
         sphere.transform.position = vec;
 
         return l;
     }
 }


pockvr.jpg (355.0 kB)
pockvr-wanted.jpg (327.3 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

2 Replies

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

Answer by streeetwalker · Oct 12, 2020 at 01:50 PM

It seems the problem is that your taking a point on the old LIneRenderer to use as the pivot for the new LIneRenderer, but because you've set up the LineRenderers as localSpace those points are local to the LineRenderers transform (i.e. referenced from 0,0,0 ).

They do not produce the rotation you want because the RotateAround is acting as though those are in world space.

So you need to first convert the pivot point you selected from local to world space. Off the top of my head you can do this with old.transform.TransformPoint( vec ) and use the result in your RotateAround call.

Your staring LineRenderer must have been set to world space, so it appears the 2nd one that you clone is rotated properly. But from thereafter you've set each new one to local space. Either that or your first one is located at 0,0,0 - in that case the points are the same as their world space equivalents.

You've got to pay for the bonus question - otherwise it's not a bonus! ;-) Jest aside, I think the problem will take care of itself once you handle the pivot point issue.

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

Answer by roroquessada · Oct 14, 2020 at 03:50 AM

Thank you so much! it works. I have to better understand these stories of spatialization ^^

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

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

211 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Line Rendering for 2D Connect the Dots Game 1 Answer

Line renderer not working 1 Answer

LineRenderer in 2D not reusing positions 0 Answers

LineRenderer not appearing as expected... 2 Answers

Two Line Renderer overlapping to create new color 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