Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by poker158149 · Aug 18, 2015 at 10:36 AM · collision2dtrailrenderertrail

Creating an infinite trail that can be collided with

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Raresh · Aug 18, 2015 at 10:58 AM

You could try spawning colliders at set intervals from the object emitting the trail while it's moving, then check if it hits one of those.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image poker158149 · Aug 18, 2015 at 02:26 PM 0
Share

This sounds like a nice idea, but - if I'm understanding this correctly - would that leave gaps in the trail in the areas that don't spawn a collider?

avatar image Raresh · Aug 18, 2015 at 02:59 PM 0
Share

Yes, but if the gap is smaller than the character, that would be enough for what you need right? I mean it doesn't have to fill the whole trail to detect with a pretty big accuracy if something entered the general area of it.

avatar image
1

Answer by tanoshimi · Aug 18, 2015 at 11:00 AM

Raycasts won't help, since they also require a collider to detect the object hit by a ray. What do you get in the Editor log after the crash?

I'd guess that the set of vertices created by that script don't define a valid polygon - seeing as you only want to detect when another player crosses the trail, have you tried using an EdgeCollider2D instead?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image poker158149 · Aug 18, 2015 at 02:45 PM 0
Share

Ah, that makes sense. The odd thing is that I don't see anything in the Editor log after the crash. But that could be because it also it's really a crash, it's more of a freeze. When it happens, the entire editor locks up and is unusable, but doesn't actually "crash." I have to open task manager and force close it.

After you mentioned EdgeCollider2D, I altered the script to use it ins$$anonymous$$d of the PolygonCollider2D, and I believe that actually fixed the freezes. In my testing that would freeze the with the PolygonCollider, it doesn't freeze with the EdgeCollider. Thanks so much for that recommendation! However, the performance is still an issue when one character moves a lot - and the performance ONLY suffers when controlling the character that has a large trail behind it. When I swap to a different character with a smaller trail, the performance picks up again. I may try putting the script on a standalone GameObject ins$$anonymous$$d of the character and simply rendering the trail to the character.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to get a glow/lightning trail effect 1 Answer

trails and particles 2 Answers

Brighter Trail Renderer 2 Answers

How to get Zerg Tentacle-like effect (see example in post)? 1 Answer

How do i make trail material separated? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges