- Home /
Question by
jj_antunes · Nov 19, 2013 at 06:35 PM ·
collisiontrailrenderer
How to make trailrenderer collider?
I´m new at unity and i'm trying to make a game with line collisions. I just found in unity forum a script that makes a trail collider. The question is that only part of that trail makes collision (the part next to the game object attached to it) and i want that the all trail collider. I think there´s something abount linecast but i can not understand what exacly. I realy neeed help. Here´s my script:
var pencil:GameObject;
var time : float = 20.0;
var rate : int = 10;
var change:String;
private var arv3 : Vector3[];
private var head : int;
private var tail = 0;
private var sliceTime : float = 1 / rate;
var hit : RaycastHit;
function Start () {
arv3 = new Vector3[(Mathf.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);
change=hit.collider.name;
}
if(change=="Sphere")
{
Debug.Log("hit change");
Destroy(Sphere);
}
}
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;
}
Comment
There are two separate working examples of this kind of code on UA. One uses Linecast() the other builds a trail of colliders. You can start here:
http://answers.unity3d.com/questions/418759/how-might-i-go-about-making-a-trail-render-that-de.html
Your answer
