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 /
avatar image
1
Question by ReCoF · Apr 18, 2015 at 04:52 PM · c#rotationlinerenderer

Rotating a LineRenderer

Hello everybody,

Before explaining my problem, i'm gonna explain you the context.

So, i want to able to select mesh triangles with a circle cursor. And it should colors the triangle touched.

My problem is the creation of the circle.

I means, this code, creates perfectly my circle :

     void Start()
     {
         LineRenderer line = GameObject.FindWithTag("MainCamera").AddComponent<LineRenderer> ();
         line.material = GetComponent<WireFrameLineRenderer>().LineMaterial;
         line.SetColors (Color.white, Color.white);
         line.SetWidth (0.2F, 0.2F);
         line.SetVertexCount(64);
         //line.useWorldSpace = false;
      }



          public void CreateCircleAroundMousePointer ()
     {
         LineRenderer line = GameObject.FindWithTag("MainCamera").GetComponent<LineRenderer> ();
         Vector3 mouse = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 20.0F));
         
         int r = 1;
         int i = 0;
         for(double theta = 0; theta < 2 * Math.PI +0.1; theta += 0.1) {
             double x = r * Math.Cos(theta);
             double y = r * Math.Sin(theta);

             float x1 = (float) x;
             float y1 = (float) y;
             
             Vector3 pos = new Vector3(x1 + mouse.x, y1 + mouse.y, mouse.z);
             line.SetPosition(i, pos);

             i+=1;
         }
     }

The circle follows my cursor very well, but it doesn't rotate...

So i tried to added it to the mainCamera and i hoped it would rotate with it, but i doesn't....

My problem is that my circle doesn't rotate when my camera is rotating around the main object. So when i'm facing it, the circle is perfectly where i need it to be but when i'm at a 90 degree angle, i just see a line (a circle view from side).

Thx for your help,

Comment
Add comment · Show 2
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 ReCoF · Apr 17, 2015 at 12:55 PM 0
Share

Actually, my camera is rotating around a gameobject wich is the center of the object that i need to see.

avatar image AlwaysSunny · Apr 18, 2015 at 04:52 PM 1
Share

I don't really remember how line renderers work, I've been using my own system to draw lines for too long. But IIRC, there's a toggle to deter$$anonymous$$e whether the line renderer uses local or world space. (absolute or relative) If I'm not mistaken, the most expedient solution would involve using local space coordinates to create the desired shape, then billboarding the line renderer's object and placing it at the mouse position in world space.

Your alternative involves some slightly more expensive and considerably more confusing math to build the circle with world-space points that respect the camera's orientation relative to the line renderer object. Unless you have a great reason to do otherwise, the best approach to a problem is often the most convenient.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Flip over an object (smooth transition) 3 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Rotate Bezier Curve around object following mouse position 0 Answers

slowly rotate a object *need quick fix* 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