Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get direction of last control point?
#1
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.
Reply
#2
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?
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply
#3
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
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply
#4
Hey _Aka_. Thanks so much for your quick support and reply to questions from your customers! Smile 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?
Reply
#5
(04-12-2023, 06:03 PM)_RicO Wrote: Hey _Aka_. Thanks so much for your quick support and reply to questions from your customers! Smile 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...wards.html
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  12_Train junction point richardzzzarnold 5 427 04-16-2025, 02:19 PM
Last Post: _Aka_
  OnAfterControlPointAdded - Control Point is null jh092 5 678 02-04-2025, 09:31 PM
Last Post: _Aka_
  How to generate gameobject on the control point Yang Yi 1 293 12-10-2024, 10:14 PM
Last Post: _Aka_
  Getting Distance from a World Point zorksox 3 446 04-16-2024, 07:30 PM
Last Post: _Aka_

Forum Jump: