- Home /
How to draw two lines at the same time that keeps overlapping each other?
Hi,
I want two different lines to be drawn at the same time where one line overlaps the other line when it passes through it.
In the image below I have two different sprites bouncing around the edges of the screen, each with its own Trail Renderer. Here, the green line is always drawn below the red one but I want it to be drawn over the red line when it passes through it. For example, in the bottom of the image I want the green line to be over the red on because it recently passed through it.
If I change the layers or Z-values it's always one line that is below the other one in all places.
It doesn't seem like I can solve this with a Trail renderer or a Line renderer, any thoughts on what I can do to solve this?
[1]: /storage/temp/151854-forumpic.jpg
Answer by sacredgeometry · Jan 26, 2020 at 12:14 PM
Assuming your photo is exhibiting the wrong behaviour as its the default one you are describing to be wrong. Then you could just render the paths in segments instead.
If you are more clever then you can before rendering each line segment get all intersections and evaluate if they should be on top or below. But you should be able to rely on render order if you are just trying to stack them.
Hi, thanks for replying.
Sorry but I don't understand what you mean by "exhibiting the wrong behaviour". How would one render the lines in segments? I have used the Line renderer and divided it into smaller segments with different z-value but it doesn't seem to make any difference in a 2D view. Either the whole line are below or over the other line and never just parts of it.
Then you may be doing something wrong because that is exactly how it works. let me make a video
https://www.youtube.com/watch?v=c_YCdCHQYQc
Is this what you are trying to do?
You were right, I was doing something wrong. I didn't think about it much but I always used the Default-Line material for the Line renderer which was what made it act like the way it did. But after doing it exactly like you did in the video with a standard material ins$$anonymous$$d it worked, so thank you very much! :)
Your answer
Follow this Question
Related Questions
How do I check if/where in a sprite another sprite is? 0 Answers
simple overlap in 2d 1 Answer
Im trying to do 2D tiling but sprites keep overlapping! 1 Answer
Erasing part of line renderer 0 Answers