Have Line Renderer Create A Line Behind The Player

Hi guys,

I have a question about the line renderer component and using it in C#.

The character in my game is going to behave similarly to the snake from the eponymous game. He’ll have a tail from where the character spawns and I want the tail to follow the player, and be created in accordance to wherever the player goes.

I’m not sure I’m explaining this well. I’ll give an example of what I want. If the player moves forward 5 metres, then left 2 metres and continues moving in that direction, there’ll be a line following where the player went.

I believe I understand what I have to do but I’m unsure about the syntax of it. Would I need to create a group of Vector3s to store the origin point and one that tracks the player’s position? If so, could someone point me in the right direction on how to start writing that?

Thanks

have a look at Unity - Manual: Trail Renderer component :slight_smile:

Can trail renderer have a collider attached to it? Is it more complicated to have a tron-like tail using the line renderer or the trail renderer?

To create a trail with colliders you’ll probably have to roll your own solution. Neither of those is capable of a Tron-like tail (that is, one that stands up vertically - both are always perpendicular to the camera), either.

If you’re trying to make a Tron tail clone, specifically, the simplest solution will probably be to use either Cubes or a plain, square Sprite. You instantiate one of them for a segment between points A and B; it sets its own position to the average of those two points and rotates accordingly; and after some period of time the line segment destroys itself.

The more complicated, but probably superior solution would be to learn to use the Mesh API to build your own trail mesh to your specifications.

I see. I’ll look into it, cheers c: