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 douglasg14b · Feb 10, 2015 at 07:27 PM · c#2dlinerenderer

How to make Line Renderer lines stay flat?

I've noticed that as I add more vertexes to a Line Renderer line the line twists and stops being a smooth line.

alt text

All lines are on the same z level, even if I remove the materials the lines still seem to twist.

I have no idea why it does this, or how to go about resolving it, any suggestions?

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 giulio-pierucci · Feb 10, 2015 at 07:33 PM

This seems a normal behaviour of line renderer.

You may use GLdraw or Graphic DrawMesh (manually creating mesh or gldraw at runtime)

GlDraw may have some occlusion problems, so you can create a dynamic mesh and draw that.

http://docs.unity3d.com/ScriptReference/Graphics.DrawMesh.html

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 douglasg14b · Feb 10, 2015 at 08:08 PM 0
Share

Thanks for the reply. So I would essentially make a mesh for each line, or a single mesh that just zig-zags with the lines? I'll read up on Draw$$anonymous$$esh.

avatar image giulio-pierucci · Feb 10, 2015 at 08:17 PM 0
Share

No!!! 1 $$anonymous$$esh -> 1 Draw (usually)

You have to set all line points on 1 mesh (vertices, triangles, indices, uv, color)

then draw 1 mesh

Like this example, that create a quad mesh (is a partial example from my project, many variables are missing, consider only the mesh creation part)

             $$anonymous$$esh mesh = new $$anonymous$$esh();
             mesh.vertices = GetVertices(targetCamera.transform, hs);
             mesh.uv = new Vector2[] { FirstUV, new Vector2(FirstUV.x, LastUV.y), LastUV, new Vector2(LastUV.x, FirstUV.y) };
             mesh.uv1 = mesh.uv;
             mesh.uv2 =  (override2uv) ? Enumerable.Repeat(SecondaryUv, 4).ToArray() : mesh.uv1;
             mesh.triangles = new int[] {    // Left bottom triangle
                 0, 1, 2,
                 // Right top triangle
                 2, 3, 0 
             };
             mesh.colors32 = Enumerable.Repeat((check == CameraSeeHaloCheck.Fading) ? GetColor(haloLayer) : color, mesh.vertices.Length).ToArray();
 
             return mesh;
 [...]
 
     private Vector3[] GetVertices(Transform targetCamera, Vector2 halfSize)
     {
         Vector3 position = (offset == 0) ? transform.position : transform.position + (transform.position - targetCamera.position).normalized * offset;
         return new Vector3[]
             {
                 position + targetCamera.right * -halfSize.x + targetCamera.up * -halfSize.y,
                 position + targetCamera.right * -halfSize.x + targetCamera.up * +halfSize.y,
                 position + targetCamera.right * +halfSize.x + targetCamera.up * +halfSize.y,
                 position + targetCamera.right * +halfSize.x + targetCamera.up * -halfSize.y
             };
     }

avatar image
2

Answer by thatCamelCode · Aug 23, 2018 at 07:47 PM

I realize this post is old, but if anyone else was trolling around the internet for a solution to this, I also found one by playing around with the LineRenderer settings that doesn't involve all this scripting.

When I did this, I was running Unity 2017.3.1f1 making a 2D game. Just go to the Alignment dropdown on the Line Renderer's settings and choose Local. This will stop the line from rotating around to match positions in space, and therefore it should appear flat the whole time.

Comment
Add comment · Show 1 · 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 chanfui · Mar 08, 2021 at 03:30 PM 1
Share

Are you saying LineRenderer2D? I'm using LineRenderer and the dropdown selection for Alignment only has View and Transform Z....

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Making a arrow instead of Linerenderer 2 Answers

Multiple Cars not working 1 Answer

Can't get linerenderers to work... 0 Answers

Distribute terrain in zones 3 Answers

Is there a way to make a Dotted Curved line in Unity for UI? 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