Line Renderer Collision

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!

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.

If its realy so small, what about edge collider then?

Agreed with Gardes. Try to use EdgeCollider.

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.

How small is too small? Maybe you can just force the distance to always be more than the threshold?

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.

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

1 Like

I am not able to get the length of a line renderer component.

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

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.

1 Like