Posts: 20
Threads: 7
Joined: Apr 2023
I'm creating a spline by "drawing" it, like in the PaintSpline example scene, but modified it a bit so that my mouse is always controlling the last point so it is smooth.
I need to have an object at the end of the line always point in the direction of the last spline control point based on the curve direction too. But it seems as though the control points don't change rotation based on direction.
Any idea how I can accomplish this?
I was thinking if there's a way to get the last control points "handle in" position, I could get a direction vector by comparing that with the current control point (last one). But not sure how to do this.
Posts: 2,110
Threads: 92
Joined: Jun 2017
Hi
I believe what you are looking for is the following:
CurvySpline.GetTangent(1f);
The method's documentation:
https://api.curvyeditor.com/840/class_fl...928ef1866c
Did this help?
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 2,110
Threads: 92
Joined: Jun 2017
Also, setting a Control Point's Bake Orientation to true will make the local rotation of the CP match the tangent/orientation of the spline
https://curvyeditor.com/documentation/sp...rientation
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Posts: 20
Threads: 7
Joined: Apr 2023
Hey _Aka_. Thanks so much for your quick support and reply to questions from your customers!
I couldn't try it right away due to the easter long weekend, but I just tried using your CurvySpline.GetTangent(1f) solution, and it seems to work (almost) perfectly. My end object is an arrow and here's what I did:
arrowDirection = LastControlPoint.GetTangent(1f);
arrow.transform.rotation = Quaternion.LookRotation(arrowDirection);
Only problem is that as soon as a point it added, it abruptly changes direction, so I had to use slerp to fix it. Although, with slerp, you can clearly see that it causes my "arrow" to flip once it rotates to a certain point. Not sure if that's the best way to smooth it out?
Posts: 2,110
Threads: 92
Joined: Jun 2017
(04-12-2023, 06:03 PM)_RicO Wrote: Hey _Aka_. Thanks so much for your quick support and reply to questions from your customers! I couldn't try it right away due to the easter long weekend, but I just tried using your CurvySpline.GetTangent(1f) solution, and it seems to work (almost) perfectly. My end object is an arrow and here's what I did:
arrowDirection = LastControlPoint.GetTangent(1f);
arrow.transform.rotation = Quaternion.LookRotation(arrowDirection);
Only problem is that as soon as a point it added, it abruptly changes direction, so I had to use slerp to fix it. Although, with slerp, you can clearly see that it causes my "arrow" to flip once it rotates to a certain point. Not sure if that's the best way to smooth it out?
If simple slerping is not good enough for your usage, try using Vector3.RotateTowards: https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html
Please consider leaving a
review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.