Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Agent-6141 · Mar 17, 2013 at 06:33 PM · trailbeamtron

How might i go about making a trail render that destroys people

I have been working on a tron game and the only thing i have left to do is make a trail render collide but i'm not sure how to go about doing that. Iv tried doing particles but i cant get the particles to come out in a wall like fashion. If anyone has any pointers please help thank you.

Comment
Add comment · Show 3
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 nsxdavid · Mar 17, 2013 at 06:55 PM 0
Share

Points for funniest question title!

avatar image Agent-6141 · Mar 17, 2013 at 07:05 PM 0
Share

how is it funny?

avatar image AlucardJay · Mar 21, 2013 at 07:15 PM 3
Share

Its funny like "I cannot destroy my children", to us that seems normal, but to a non-programmer .... =]

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Mar 17, 2013 at 07:24 PM

Take the game object the TrailRenderer is attached to and add a Collider and a Rigidbody. Move the object through physics (AddForce() for example), and check for collisions. If you are using a character controller, you can use OnControllerColliderHit() and have the player object detect the collision.

I smiled at your title too after @nsxdavid pointed it out since "people" can be taken to be real people or game objects.

Comment
Add comment · Show 28 · 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 Agent-6141 · Mar 21, 2013 at 06:19 PM 0
Share

I have figured out how to make it hit like the walls and stuff but im a noob at scripting so i cant figure out how to get it to hit the trail renderer because the trail renderer isnt like phisical but a wall is. Also how do i use OnControllerColliderHit() im sorry i just dont understand

avatar image robertbu · Mar 21, 2013 at 07:03 PM 0
Share

I misunderstood your question. I assumed you were talking about something like a fireball with a tail where the head of the fireball is that you need to test. From this comment, you want any part of the line to be detected. That is a tail exists and you want a player who runs into the tail to be detected. Probably the easiest is to keep an array of Vector3 positions of the head of the trail renderer. I'd sample less frequently than every frame...5 or 10 times a second. Then you can do a Physics.LineCast() between the points to see if anything intersected. As a "noob at scripting" you may find this a bit challenging. I likely use something called a "circular list" implemented with Unity's build-in arrays and a head and tail index. Since the trail renderer is based on time, given the sample rate and the time, you will know how large the array needs to be. Note this will not detect edge hits, only something that intersects with the middle of the trail.

avatar image AlucardJay · Mar 21, 2013 at 07:15 PM 0
Share

Think 'Tron Light Cycle' =]

alt text

Have a look at this : http://answers.unity3d.com/questions/285040/draw-a-line-in-game.html

avatar image natxein AlucardJay · Mar 28, 2016 at 06:51 PM 0
Share

Hi! I have used your script (below) and it works great! but I´m trying to make the trail longer in runtime (like snake game) and I am unable to make it works fine... I increment the time of trail renderer and time in your script and create a new array Vector3[] copyArv3 with the new length, copy the old arv3 to the new one and create again the Vector3 arv with the new length and copy the old data again... but I´m missing something and I don´t know how to fix it, could you help me please?

thank you!!!

avatar image robertbu · Mar 21, 2013 at 08:45 PM 0
Share

Take a look at @alucardj 's link. The solution will work with the fringe as well as the center of the LineRenderer. I'm impressed at the links he's always posting.

Here is a bit of code that implements the simpler idea I had. It only works if the object passes through the longitudinal axis of the tail. Note you could add additional hit conditions or process multiple hits inside the Hit() function.

 #pragma strict
 
 var time : float = 2.0;
 var rate : int = 10;
 
 private var arv3 : Vector3[];
 private var head : int;
 private var tail = 0;
 private var sliceTime : float = 1.0 / rate;
 var hit : RaycastHit; 
 
 function Start () {
     arv3 = new Vector3[($$anonymous$$athf.RoundToInt(time * rate) + 1)];
     
     for (var i = 0; i < arv3.Length; i++)
         arv3[i] = transform.position;
     head = arv3.Length-1;
     StartCoroutine(CollectData());
 }
 
 function CollectData() : IEnumerator {
     while (true) {
         if (transform.position != arv3[head]) {
             head = (head + 1) % arv3.Length;
             tail = (tail + 1) % arv3.Length;
             arv3[head] = transform.position;
         }
         yield WaitForSeconds(sliceTime);
     }
 }
 
 function Update() {
     if (Hit())
         Debug.Log("I hit: "+hit.collider.name);
 }
 
 function Hit() : boolean {
     var i = head;
     var j = (head  - 1);
     if (j < 0) j = arv3.Length - 1;
     
     while (j != head) {
         
         if (Physics.Linecast(arv3[i], arv3[j], hit))
             return true;
         i = i - 1; 
         if (i < 0) i = arv3.Length - 1;
         j = j - 1;
         if (j < 0) j = arv3.Length - 1;
     }
     return false;
 }
avatar image Agent-6141 · Mar 22, 2013 at 06:46 PM 0
Share

Thanks ill try this out, here's a link if you want to see how far i have gotten on this game. http://www.youtube.com/watch?v=V4mNjj$$anonymous$$gsGQ

Show more comments
avatar image
3

Answer by noooodley · May 10, 2014 at 07:21 PM

This is a bit late, but I wrote a script for a trail renderer that detects 2D collisions. You can find it on the Unity wiki: http://wiki.unity3d.com/index.php/TrailRendererWith2DCollider.

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 pranav_ps95 · May 20, 2019 at 09:18 AM 1
Share

For some reason your script does not work as it used to in Unity 2019 version. It worked fine until 2018 version. I was not using it for detecting collisions, but I was using it because unlike the default trail renderer, this renderer would not change its view when the player object turned or moved (did not change alignment with respect to camera) and therefore was perfect to highlight the path the player took. Could you help here ?

avatar image
0

Answer by Agent-6141 · May 22, 2019 at 10:49 PM

This is crazy that this thread is still rolling hahaha @pranav_ps95

Here is a link to a video that contains all my project files for when I worked on this a long time ago, if you look at my scripts, you may find what you need

https://youtu.be/V4mNjjMgsGQ

Comment
Add comment · 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

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do i make a tron like effect for trail renderer 2 Answers

Assigning new sharedMesh to mesh collider every frame doesn't work? 1 Answer

Box colliders as trail 0 Answers

Raycast trail renderer? 3 Answers

Problem with trial render 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