- Home /
Hide linerenderer positions
I have a Line that's going through a Portal the Problem is that the line connecting the 2 Portals is still visibel. Is there any way to hide lineparts from the linerenderer.
I want that the line part with the red on it is not visibel.
Answer by darksider2000 · May 09, 2020 at 11:37 PM
Hi again @OneCode-Official
Are you using a LineRenderer or did you perhaps mean TrailRenderer? I'm guessing this line/trail is attached to your ball that's going through a portal.
I would suggest using a trail renderer with a script that calls on the "emitting" bool. Whilst emitting is off new vertices won't be created for the trail, but the old ones stay where they are. Then when you turn it back on again your trail continues from where you are.
Here you can see a game object with a trail attached to it moving through triggers 1 and 2 left to right(Green circles), when they enter a trigger the emitter's value is flipped:
The code used for this example:
public class TrailRendererStop : MonoBehaviour
{
public TrailRenderer trail;
void OnTriggerEnter2D(Collider2D other) {
trail.emitting = !trail.emitting;
}
}
Hope this helps!
This is pretty cool and I could use this in one of my other games but it's not what I am searching for. Here's a picture of my game.
So The blue things are portals and I am using a linerenderer. I don't want that you see the line being connected with the two portals. So I somehow need to hide the connection from point 3 to 4.
Yeah I see what you mean now. Why don't you just use multiple lines?
If you only use one line you'd have to modify the line's curve like richardkettlewell suggested. This is not only complicated because of the math but also limits you in the sense that any change you make in the scene will need a corresponding change in the code. Unless you create a function that generates a curve, which is just as tricky as it sounds.
Using multiple lines you have the freedom to manipulate the scene around, and don't have to do the math.
Just draw a line from start to portal 1. Then another from portal 2 to finish, etc.
Answer by richardkettlewell · May 10, 2020 at 12:33 PM
Darksider’s answer is a good suggestion.
The emitting flag in the trail renderer is actually just overriding the trail width to be zero.
So you can emulate the same thing in the line renderer by setting up an appropriate width curve that is zero at the bits you need to hide. You need to know the percentage along the entire line to use this trick.
Your answer
Follow this Question
Related Questions
LineRenderer: how to draw line intersections? 1 Answer
LineRender width not consistent across resolutions 1 Answer
tilemap 2d rendering on Y plane 0 Answers
Sprite not visible from behind 0 Answers