06-27-2022, 08:06 PM
I am supporting a "Snap" to line feature. When doing this, I noticed a problem.
Here is a simple example of three control points A, B, C along the X-axis so all Y values are zero. Z values are also initially zero.
The Handle<In,Out> of all 3 cps are locally set along the X-axis also +-0.39f. This produces the expected two straight segments AB, and BC.
See attached image "Before Move CP3" (not sure how to place in in-line here without posting them to a URL?)
In the Unity Console window you can see the output of calling [CP0000].GetTangent(1).z and [CP0001].GetTangent(0).z These 'z' values are correct (full value is (1,0,0)). I tried both CPs to be sure I understood they should be the same.
Next I move the position of CP0003 only in Z to create a curve setting its AutoHandles = true (Does the order matter here: update position first, then auto-handle or vise-versa?
See attached image "After Move CP3"
Note that in the Console window, the same GetTangent calls are now returning 0.008 for what the tangent now is at CP0002. This was unexpected.
Later, I was use this tangent to snap CP0003 (segment BC) back to a align with segment AB. Because the tangent of AB is no longer (1,0,0) but instead (1,0,0.008) the snap doesn't align.
It is an easy work around by calculating the tangent on my own (A-B).Normalize.
But is this a bug, or did I do something wrong setting up CP0003 for the curve, or do I just not understand GetTangent? In the later case, I assumed it would return a the (1,0,0) vector because the curve starts after CP0002 so at CP0002 it is still straight.
Please let me know how this should work as a full understanding is needed for other places where we may use GetTangent.
Here is a simple example of three control points A, B, C along the X-axis so all Y values are zero. Z values are also initially zero.
The Handle<In,Out> of all 3 cps are locally set along the X-axis also +-0.39f. This produces the expected two straight segments AB, and BC.
See attached image "Before Move CP3" (not sure how to place in in-line here without posting them to a URL?)
In the Unity Console window you can see the output of calling [CP0000].GetTangent(1).z and [CP0001].GetTangent(0).z These 'z' values are correct (full value is (1,0,0)). I tried both CPs to be sure I understood they should be the same.
Next I move the position of CP0003 only in Z to create a curve setting its AutoHandles = true (Does the order matter here: update position first, then auto-handle or vise-versa?
See attached image "After Move CP3"
Note that in the Console window, the same GetTangent calls are now returning 0.008 for what the tangent now is at CP0002. This was unexpected.
Later, I was use this tangent to snap CP0003 (segment BC) back to a align with segment AB. Because the tangent of AB is no longer (1,0,0) but instead (1,0,0.008) the snap doesn't align.
It is an easy work around by calculating the tangent on my own (A-B).Normalize.
But is this a bug, or did I do something wrong setting up CP0003 for the curve, or do I just not understand GetTangent? In the later case, I assumed it would return a the (1,0,0) vector because the curve starts after CP0002 so at CP0002 it is still straight.
Please let me know how this should work as a full understanding is needed for other places where we may use GetTangent.