According to the Hairy Ball theorem, it is not possible to get consistently oriented normals at any point on the curve.
What I want to achieve is a game object moving beneath a procedurally-generated rail (plain cylinder). To generate a tube I use a spline which consists of bezier curves. Thus, I need to get a correctly oriented normals at any point of the curve.
The code looks like this:
Vector3 q2 = GetCurveTangent (...);
Quaternion lookAt = Quaternion.LookRotation (q2);
Vector3 normal = lookAt * Vector3.up;
normal = Quaternion.AngleAxis (angle, q2) * normal;
return point + normal * size;
Which generates the following normals:
On horizontal segments everything is correct, but on vertical ones, when tangent is oriented like Vector3.up, everything goes wrong.
The only advice I’ve received is to try and use the previous tangent instead of global up vector. But I can not get any good result out of it. What I tried to do is:
Quaternion lookAt = Quaternion.LookRotation (q2, previousNormal);
but it is not clear what to place here:
Vector3 normal = lookAt * ?
And any combination of tangent, normal and rotation gives me something like this:
So, the question is: how can one create a cylindrical rail and an object moving beneath it (using the normal facing strictly down the curve)? If curve is vertical, “down” is of course globally forward and so on.