Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity Pro - Draw Line

Discussion in 'Scripting' started by ribesvictor, May 26, 2011.

  1. ribesvictor

    ribesvictor

    Joined:
    Oct 18, 2010
    Posts:
    20
    Hi all,
    I need to draw some 3D lines in my scene, like GL.Lines do. But I need to change the width of the lines.
    I have Unity Pro, but I don´t know if it´s possible.

    I´ve tried to do it using GL.Quads, but my app becames very slow.

    Do you have some ideas? Thank you so much.

    ribesvictor
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There isn't a way to change line width that I know of, aside from using GL.Quads, which you already tried. (There's always Vectrosity...it creates lines by using meshes.)

    --Eric
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thumbs up for vectrosity here too.
     
  4. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    OK, so I got to tinkering with the concept without GL.Quads. (mostly because I dont know how to use them) and what it basically comes down to is the ability to create four points based on a width from a start point to an end point. So I made four boxes and set on the task of pin pointing where the edges of the vertices of the line should be. It is essentially a quad.

    In my earlier tinkerings with 3d I found a wonderful method called Cross. (or CrossProduct in Newton game dynamics) Way back in the day I used it to calculate the force making something go sideways. The better use here is to figure out the side movement of a point based on the heading of the camera. I came up with this function:

    Code (csharp):
    1.  
    2. function GetCross(position : Vector3){
    3.     var direction=Camera.main.transform.position - position;
    4.     return Vector3.Cross(Camera.main.transform.forward, direction).normalized;
    5. }
    6.  
    This returns a normalized cross product which all you then have to do is add to a point (or subtract for the other side multiplied by the half width. This gives you the 4 points for a line of x width facing the forward direction of the camera.

    Incredibly simple, endless possibilities.
     
  5. ribesvictor

    ribesvictor

    Joined:
    Oct 18, 2010
    Posts:
    20
    Thanks for the information. Eric, I´ve seen vectrosity and it seems very powerful, but I only need to draw a few simple lines. This is the reason that i´m looking for something free, but thank you, anyway, It´s possible that I´m paying for it in a close future.

    I´ll try your idea BigMisterB. Thank you :)