- Home /
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.
Its funny like "I cannot destroy my children", to us that seems normal, but to a non-programmer .... =]
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.
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
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.
Think 'Tron Light Cycle' =]
Have a look at this : http://answers.unity3d.com/questions/285040/draw-a-line-in-game.html
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!!!
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;
}
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
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.
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 ?
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
Your answer
Follow this Question
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