05-30-2022, 08:07 PM
Ok... I think I figured it out. I need to set the Spline.Orientation to static and then make sure the Z-rotation of the CP's are set to 0.
I want the flat spline path to stay parallel to the ground plane (XZ), not to bank, even if the spline all over the place.
For example, old "Slinky" toy was a flat spiral. Or a road twisting through the mountains (assuming they don't try to bank the curves for speed) is best flat, side-to-side across the road.
I will code this to see if this does it. If you know of a better or more proper way, please suggest.
Seems to work!!
I want the flat spline path to stay parallel to the ground plane (XZ), not to bank, even if the spline all over the place.
For example, old "Slinky" toy was a flat spiral. Or a road twisting through the mountains (assuming they don't try to bank the curves for speed) is best flat, side-to-side across the road.
I will code this to see if this does it. If you know of a better or more proper way, please suggest.
Code:
Vector3 localFinalPos = trackSpline.transform.InverseTransformPoint( worldPos );
var cp = trackSpline.Add( localFinalPos, Space.World );
var euler = cp.transform.rotation.eulerAngles;
cp.SetRotation( Quaternion.Euler( euler.x, euler.y, 0 ) );