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

Line Renderer Collision

Discussion in 'Physics' started by RedKinetic, Jun 12, 2015.

  1. RedKinetic

    RedKinetic

    Joined:
    Nov 9, 2014
    Posts:
    20
    Hello,

    I have a line being drawn on screen, then I add a box collider to this line. If the line drawn is too small, it says the vertices are too small and close together and do not generate a collider, then other objects pass right through it. I currently have the line's rigidbody to interpolate and isKinematic.

    Know of any ways to override this and generate a collider anyways, or make it more efficient?
    The line is being drawn by a user's touch on screen.

    Thanks!
     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    You can maybe scale your whole scene so that everything looks the same, but to unity you now have a bigger collider.
    Or maybe you can instead use a regular box collider and just make it really flat.
     
  3. Gardes

    Gardes

    Joined:
    Apr 7, 2015
    Posts:
    46
    If its realy so small, what about edge collider then?
     
  4. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
  5. RedKinetic

    RedKinetic

    Joined:
    Nov 9, 2014
    Posts:
    20
    I tried to use EdgeCollider2D, but when the user draws lines, the edge colliders added just stop being added to the line after a certain length. If a user draws a medium/long line, only a few colliders are being created at run time that cover about half of the line.

    My scene is scaled proportionally. Any larger or smaller and the graphics become distorted.
     
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,462
    How small is too small? Maybe you can just force the distance to always be more than the threshold?
     
  7. RedKinetic

    RedKinetic

    Joined:
    Nov 9, 2014
    Posts:
    20
    I do not know how to do so. I tried drawing a raycast/linecast along the users touch to match the line renderer being drawn, but wasn't able to complete that, either.
     
  8. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    In your line drawing method, are you able to get the lines current length? If so, do a check if the line length is less than a certain amount, just make the line equal to that certain amount.
    To get its length, when you are setting the lines positions do a vector3.distance check and if the distance is to small, add to the second distance the amount you need to add in the direction the line was going.

    Here is info on direction and distance of vectors
    http://docs.unity3d.com/Manual/DirectionDistanceFromOneObjectToAnother.html
     
    Last edited: Jun 17, 2015
    LaneFox likes this.
  9. RedKinetic

    RedKinetic

    Joined:
    Nov 9, 2014
    Posts:
    20
    I am not able to get the length of a line renderer component.
     
  10. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Then how are you creating the line? I assume you are feeding it vector3s? If so, grab those vector3s before doing SetPosition on the linerenderer and check the distance.

    This is a link to a TrailRendererWith2DCollision script. Not sure if it works (and its trail renderer, not line), but just in case...
    http://wiki.unity3d.com/index.php/TrailRendererWith2DCollider
     
  11. RedKinetic

    RedKinetic

    Joined:
    Nov 9, 2014
    Posts:
    20
    So I largely fixed the issue with this. I just checked if the collider was too small to be added, then i made it a little bigger so it renders.
     
    HiddenMonk likes this.