- Home /
Trail Renderer leaving streaks from last position
I'm trying to make a swipe trail on a touch position and I'm having issues.
Currently when I press mousebuttondown the trail starts, and when mousebuttonup it disappears. (which is exactly what I want).
But if I start a new trail on mousebuttondown in a new position, the trail starts from the last mousebuttonup position and glitchily streaks across to the pos of the new mousebuttondown.
I've completely stripped my code of all excess (before I was trying to attach a hit collider) and I'm still having the same problem.
Can't find anyone else having the issue and I'm at wits end with this.
And the code I'm using:
public class Swipe2 : MonoBehaviour { void Start() { Cursor.visible = false; }
void Update()
{
Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = pos;
}
}
Answer by unity_ek98vnTRplGj8Q · Oct 13, 2020 at 08:55 PM
You can use TrailRenderer.Clear() to erase the history of the trail renderer before you move it to a new distant position.
Hi, thanks for the fast reply.
I tried implementing it in my code, but it's still leaving a trail (I have attached the script to a gameObject with the Trailrenderer component on it)
This is my code if you could provide me with any pointers I would really appreciate it.
public class Swipe2 : $$anonymous$$onoBehaviour { private TrailRenderer tr;
// Start is called before the first frame update
void Start()
{
tr = GetComponent<TrailRenderer>();
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.position = pos;
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
StartSwipe();
}
if (Input.Get$$anonymous$$ouseButtonUp(0))
{
StopSwipe();
}
}
void StartSwipe()
{
}
void StopSwipe()
{
tr.Clear();
}
}
Have you tried putting it in StarSwipe instead?
Works like a charm! Thanks a bunch!
I thought that if I had placed it there it would clear the trail while it was swiping, but it doesn't.
Thanks again!
Your answer
Follow this Question
Related Questions
Trail renderer lag issue 1 Answer
Trail renderer looks weird when there is a change of direction 1 Answer
Trail renderer on top of player object 0 Answers
Trails in just one direction 1 Answer