Is it possible to do as shown in the picture depending on the distance? That is, if the line is less than a certain distance, it is colored green. The distance that the line has exceeded is colored yellow.
You can make it whatever color you want. The LineRenderer uses a Material, and you can use any Material you want.
@PraetorBlue It turns out that to make two colors on one line, you can apply a specially prepared one material. Or do I need to apply two materials for one line?
But the main question is different. Is it possible to make color dependent on line distance? For example, a line has a size of 20 units. Up to 10 units the line is colored green, from 10 to 20 units yellow. If the line has a size of 12 units, then from 10 to 12 is yellow.
Yes it is of course possible. You need only to write the shader that does it.
Or you could have two line renderers, one starting when the other one ends. Probably the easiest.
@PraetorBlue . The only thing I know about shaders is that they exist. Therefore, I have a few questions. Are shaders able to take data from a script or send data to a shader by a script? For example, I have three variables. “DistTotal” is the total length of the line, it consists of “Dist1” which is green + “Dist2” which is yellow. The render line itself has an unknown length, because I asked a question in one of the topics how to find the total length of the render line consisting of many dynamically created points, no one answered me. So, what exceeds “DistTotal” should not be displayed.
I had a couple of cases when, after learning something new, I found out that it was useless. If this can be done using a shader, could you tell me where I can read about it.
The thing is, I don’t know where it ends. This line represents the path the character must take. I’m using the pathfinding library, how it works I don’t know. I asked on their forum a very big question on this topic with a picture, no one answered me there.
I would be grateful if you could describe these options in more detail. Or where can I read about them?
“The pathfinding library”? There are many!
What you were showing in the picture didn’t in any way include pathfinding, it’s just a straight path. Do you want to draw a line along a path?
There is only one pathfinding library for a unity! https://arongranberg.com/astar/ I have never heard of others. This is how the path is drawn using the library.
AILerp ai2;
LineRenderer lin;
ai2.GetRemainingPath(buffer, out bool stale);
lin.positionCount = buffer.Count;
lin.SetPositions(buffer.ToArray());
The picture shows a masterpiece of the past. From there I copy the core mechanics. That’s a bad screenshot. There, a full-fledged path search is implemented and there is a dependence on the distance. I almost made this mechanic. It remains to colorize the linear render. And due to the fact that I could not limit it, I had to do it a little differently, it works fine but not perfect.
Well, okay, you have a list of positions in the buffer. That gives you line segments. Grab line segments while their combined length is less than 10. When you get to the line segment that would pass you over 10, split it into two. Pass all the points you have grabbed to the first line renderer, and pass the remaining to the second one.
@Baste I thought about it. I’m pretty sure these segments are different sizes. If use this method, then need to find an additional point. And the distance to this point should depend on the variable “Dist1”. Then you need to make two lists of points and initialize the prebuff with line rendering at an additional point or activate the prebuff with line rendering that will be located at the end point of the path display. If it is possible to do this, then how to find this additional point? What should be used for this?