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?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
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
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
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/Vector3.RotateTowards.html
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Avoiding runtime GC allocations on control point position change Ell223 8 18 02-24-2024, 10:43 AM
Last Post: _Aka_
  Connection "next' control point jh092 3 15 11-22-2023, 11:47 AM
Last Post: _Aka_
  Spline.Length not updated unless I add a point to spline (or modify it) first. _RicO 3 6 08-26-2023, 08:41 AM
Last Post: _Aka_
  Custom Control Nodes Lupos 3 14 05-27-2023, 09:05 PM
Last Post: _Aka_

Forum Jump: