Search Unity

Draw visio-like lines between objects

Discussion in '2D' started by willthiswork89, Oct 29, 2014.

  1. willthiswork89

    willthiswork89

    Joined:
    Oct 31, 2013
    Posts:
    5
    Hey all,
    I'm looking for some ideas on how to implement "snap-lines" between two objects that can essentially bend around other objects at 90 degree angles. I think i'll need to use a line renderer to achieve this but any help with ideas on finding the "bend" points would be appreciated.

     
  2. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    hi aye, just my 10p worth.

    I guess, that it has to go from point A (Ax, Ay), to point B(Bx, By), with one 90 degree bend.

    by the looks of it, they go in either one of two ways that includes two lines to be rendered between three points, just off the top of my head.

    either it draws vertically from start to target Y value first, then horizontal from there to target point.
    (Ax, Ay -> Ax,By -> Bx, By)
    or
    draw horizontally from origin to target X value first, then vertically towards target.
    (Ax, Ay -> Bx,Ay -> Bx, By)


    just me thinking out loud to get ball rolling :)
     
  3. willthiswork89

    willthiswork89

    Joined:
    Oct 31, 2013
    Posts:
    5
    Thanks Oboshape, it does get a little more complicate if another object is in the way then you have to "bend around it" but i definitely understand what you are saying. For a concept to start that would do but end game i would definitly want to be able to bend around objects.
     
  4. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    would the line be avoiding following 90 degree angles? if its say a box sprite it hit? that is over and above the basic L shape of the line.
     
  5. willthiswork89

    willthiswork89

    Joined:
    Oct 31, 2013
    Posts:
    5
    you would stick to 90 degree angles, its okay to have multiple ones but if it hits a sprite the idea would be to bend around it
     
  6. willthiswork89

    willthiswork89

    Joined:
    Oct 31, 2013
    Posts:
    5
    Alright guys i give up, i got the line renderer in and it does this strange tapered effect on the line instead of leaving them square.. The problem goes away if i remove the last vertice.

    LineRenderer lRenderer = mLastClickedConnector.gameObject.AddComponent<LineRenderer>();
    lRenderer.SetWidth(.06f, .06f);
    lRenderer.SetVertexCount(3);

    lRenderer.SetPosition(0,new Vector3(mLastClickedConnector.transform.position.x, mLastClickedConnector.transform.position.y));
    lRenderer.SetPosition(1,new Vector3(mLastClickedConnector.transform.position.x, pColliderClicked.transform.position.y));
    lRenderer.SetPosition(2,new Vector3(pColliderClicked.transform.position.x, pColliderClicked.transform.position.y));
     

    Attached Files:

  7. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    I havent really used these apart from a couple of tutorials.

    I was having a dig around this morning to see what i could find, there was a couple of mentions of postings here in the forums with line renderers that look like theyre rotated. but i cant find any concrete answers, sorry :(