- Home /
Activating and de-Activating trail Renderer
I am trying to make a pen which writes with a trail renderer when the tip of the pen is colliding with the paper. When the pen is not on the paper I want it to stop the trail renderer, but at the same time keep the lines it previously made.
Is there any way possible where I can de-Activate the trail renderer on my object but keep the lines that it previously made?
Answer by laCarr41 · Jun 13, 2013 at 05:44 PM
Ok well, I did not figure out how to do exactly what I Originally asked, but I did a little magic trick instead. I have two objects, The first is a Pen which is above the drawing surface, The second is the Pen tip which is under my drawing surface. When the Pen gets closer to the drawing surface from above, the Pen tip get closer from the back. Eventually the pen tip with the trail renderer becomes visible and it looks as if the pen is drawing. I know that this has some flaws and will not work if your surface is not wide enough to hide the Pen.
This does not deserve to be the correct answer to my problem, but it is more of an alternative solution.
Answer by Hyperion · Jun 13, 2013 at 12:45 AM
Well, I mainly only have a solution to 1 part of your question. That is to keep trail. All you need to do basically is make the time variable very very high or put 'infinity' there (at least infinity should work...although I haven't tried it yet). Also if you haven't done so, might I suggest making the MinVertexDistance very low as well, since that makes the trail smoother.
As for the second issue, you could try something like the following adapted to a trailrenderer.
gameObject.GetComponent(ParticleEmitter).emit= false; //tell the emitter to stop
Thanks! Helped a lot. Still need a little help with the second part. Is there any other way I could accomplish this task other than using a trail renderer?
You're welcome. Hmm..... There are multiple ways of doing this. You could give the paper animations that give it ink (basically change the texture every second) and fake the pen writing, but that's really hard...
OH got an idea! You could use a simple particle emitter at the tip of the pen/ the part that writes. The particles should not follow the pen so if you move it around, they'll stay. Plus you can make the particles look like ink. Unity's particle emitter has a function called Pause. So that might be able to solve your second problem.
Thanks for all of the ideas. If I run into trouble with my solution, I'll look into your solution. If you or anyone wanna know more about what I did send me an email and I'll get my code posted up.
Cool! Also, could you please help me with a question of $$anonymous$$e called something like 'Run to walk issue'? I would really appreciate it.
I will take a look at it, but I am very new to unity, so I will do my best!
Answer by Dominic12 · Oct 07, 2018 at 03:30 AM
I wanted to disable the renderer when not using an attack so i just changed the width to zero. Example:
private TrailRenderer tr; void Start () { tr = GetComponent(); }
void Update () {
if (Input.GetKey ("w")) {
tr.widthMultiplier = 0.0f;
}
if (Input.GetKey ("1")) {
tr.widthMultiplier = 3.0f;
}
}
Your answer
