I have a ball rolling through the tube, and after ever roll I do a raycast down, and then get the normal of that point so I can get the difference between it and the initial raycast and then rotate the ball can be parallel to the ground. The problem is, the tube is made up of a series of triangles, as most things are. If I got the normal of the present triangle it would point strait up, but because of there the ball is the ray is casting down on an edge between two triangles and the normal is pointing at an odd angle. In the picture the green is the raycast, and the red is the normal. Is there a way that I can tell the difference between triangle proper and an edge between two triangles. I’ve included my code so you might better understand what I am trying to do.
//Move ball down onto the surface.
Physics.Raycast(down.position, -down.up, hit);
transform.position.y -= (hit.distance - transform.GetComponent(SphereCollider).radius*scale);
//Rotate the ball around a point very close to where the ball is touching the tube, it will roll but will be elevated slightly which is why it has to be brought back down in the above code
Physics.Raycast(child.position, -child.up, hit);
transform.RotateAround(hit.point, child.right, 5);
//rotate the children to realign
child.Rotate(child.right * -5);
down.Rotate(down.right * -5);
Debug.DrawRay(down.position, -down.up, Color.green, 5);
//Rotate children so we can find what the normal of the surface is.
Physics.Raycast(down.position, -down.up, hit);
//if surface is an edge rotate by a little
Debug.DrawRay(hit.point, hit.normal, Color.red, 5);
rot = -Vector3.AngleBetween(down.position, hit.normal);
child.Rotate(child.right * rot);
down.Rotate(down.right * rot);
[3312-screen+shot+2012-09-06+at+10.53.25+pm.png|3312]