Hey all.
I have a setup where I want little lightning arcs to appear along the surface of a hand mesh in my scene. So ive done the following:
Get the array of vertices in the hand mesh->pick 3 random points from that array-> use those points as start, middle and end positions of my linerenderer, that does the lightning effect.
This procedure is flawed, in that it could give me lightning inside the handmesh, im aware of that, but thats a different issue. The issue I THINK im having is that, the positions I feed to the linerenderer are interpreted as worldspace coordinates, and I want it to think of them as objectspace (Along the hand mesh).
Could this be what is going on? I post my code, and a screenshot of the scene +inspector where the position vectors are shown(they dont deviate all the much from the values in the screenshot).
Code first:
var lightningWidth = 0.05; // line renderer line width
var numVertices = 10; // number of line segments per bolt
function FixedUpdate() {
var mesh : Mesh = GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var lr = GetComponent(LineRenderer);
var temp_start_point:Vector3;
var temp_middlepoint1:Vector3;
var temp_end_point:Vector3;
var start_point:Vector3;
var middlepoint1:Vector3;
var end_point: Vector3;
temp_start_point = vertices[Random.Range(0,vertices.Length)];
temp_middlepoint1 = vertices[Random.Range(0,vertices.Length)];
temp_end_point = vertices[Random.Range(0,vertices.Length)];
//Debug.DrawLine(Vector3.zero,start_point,Color.red);
lr.SetWidth (lightningWidth, lightningWidth);
lr.SetVertexCount (numVertices);
start_point = temp_start_point+transform.position;
middlepoint1 =temp_middlepoint1+transform.position;
end_point = temp_end_point+transform.position;
lr.SetPosition(0, start_point);
lr.SetPosition(1, middlepoint1);
lr.SetPosition(2, end_point);
}