I’m creating a 2D platformer where the player controls multiple characters that each leave a trail behind them. The trails last until the player completes the level.
If one of the characters crosses the trail of another character, I need to perform an action on the character that crossed the trail. The built-in TrailRenderer is perfect for creating the trail, but does not provide me with a way to detect collisions with it.
I found a script that is supposed to provide a solution to this (TrailRendererWith2DCollider) but I’m having serious issues with it.
It creates a PolygonCollider2D around the trail and updates the path of the collider every frame. The issue is that this script completely crashes my engine if I run the game in it, and it crashes the game if I run it standalone. I’ve traced the issue back to the collider.SetPath(0, colliderPath); call. For some reason, the SetPath call eventually crashes everything with no reason why. Debugging gets me nothing and there’s no errors. Also, after the trail gets long enough, the performance starts to suffer severely. If I disable the SetPath call, nothing crashes and I have no performance issues.
Is there a way to use the built-in TrailRenderer and detect objects that pass over the path of the trail? Others have mentioned RayCasts, but I’m not super familiar with them and I think they require points of the path in order to cast the ray to, but as far I know you’re not able to get the points of the trail using the build-in TrailRenderer.
Any and all help would be greatly appreciated! Thank you to everyone who takes the time to read this.