- Home /
Player leaving a solid trail with a collider like in a snake like game,Leave a solid trail with a collider in a snake like game
I'm trying to make a 2d game right now, where all players are small dots that leave a solid trail behind them so you cannot "drive" through your own or other player's trails.
I'm relatively new to Unity so I'm kinda puzzled right now. Any ideas on how to do that? I already read up on Composite Collider 2D but I don't think it really is what I want :/
Maybe something with a line renderer? But I'm not familiar with that aswell. I've found a few solutions but those are years old and didn't work when I tried them out :(
Hope someone has an idea!,I'm trying to make a game right now, where all players are small dots that leave a solid trail behind them so you cannot "drive" through your own or other player's trails.
I'm relatively new to Unity so I'm kinda puzzled right now. Any ideas on how to do that? I already read up on Composite Collider 2D but I don't think it really is what I want :/
Maybe something with a line renderer? But I'm not familiar with that aswell.
Answer by Llama_w_2Ls · Jan 29, 2021 at 07:49 AM
In the snake game, a way I would do it, is just to instantiate a box-like dot, at the snake's tail whenever it gets bigger. Each section of the snake, therefore, has its own box collider. No need for messing around with complex meshes anymore.
Anyway, the way this would work is, when a key press is detected, it might leave a mark on the board, then, whenever any box collider (section of the snake's tail), enters that mark, it changes direction. I'll help you out further if you need it. This should create a trail-like snake game.
Answer by LeHoppel · Jan 29, 2021 at 07:55 AM
Hey thanks for answering!
Sorry I think my description is a bit misleading. I don't want the trail to follow the "head"/the player but rather that all players leave solid "walls" where they go. Imagine it like this: everybody has the same speed and you can only win by outmaneuvering your enemies or to wait until they all drive either into the level border or someone's trail.
I've also read up on a snake game tutorial but the big difference is that my trail grows constantly and not just when the snake eats. Thus I would create dozens of gamwobjects per seconds with such an approach I think
Ah ok. Well one thing you might want to look into is combining meshes. This allows you to instantiate lots of gameobjects, and combine them into one, with one single complex mesh collider in your scene. This way, whenever you move, you can instantiate a block and combine it to your current trail. You might find this helpful. @LeHoppel
I posted my answer as a standalone comment greeaat...
Thank you very much; I'll have a look into that!
Your answer
![](https://koobas.hobune.stream/wayback/20220613024138im_/https://answers.unity.com/themes/thub/images/avi.jpg)