Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add a new point with a smooth curve?
#1
Hello

Excuse my crude drawing, but essentially I want to add two points by code and have a trajectory like in the picture.

I'm using .Add() and changing their rotation afterwards but ofc this only gives me a straight line

[Image: trajectory.jpg]

So how would I go about doing this? anyone got a lead?

Thanks


Attached Files Image(s)
   
Reply
#2
Hi, you have to change the interpolation type of the spline to something else than linear
Reply
#3
(03-19-2021, 07:13 PM)athos_k Wrote: Hello

Excuse my crude drawing, but essentially I want to add two points by code and have a trajectory like in the picture.

I'm using .Add() and changing their rotation afterwards but ofc this only gives me a straight line

[Image: trajectory.jpg]

So how would I go about doing this? anyone got a lead?

Thanks

It depends on what your need to do, but often times setting a spline's interpolation mode to Bezier, then setting the Bezier handles of the control points gives the most flexible solution:
See CurvySplineSegment.HandlesIn and similar, and CurvySpline.Interpolation
In general, whatever you want to do via code, do it first via the editor, and see if you get the expected result. Rotating a control point via editor will not get the result you expect (or at least what I understand is your expectation)
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
(03-21-2021, 07:00 PM)_Aka_ Wrote:
(03-19-2021, 07:13 PM)athos_k Wrote: Hello

Excuse my crude drawing, but essentially I want to add two points by code and have a trajectory like in the picture.

I'm using .Add() and changing their rotation afterwards but ofc this only gives me a straight line

[Image: trajectory.jpg]

So how would I go about doing this? anyone got a lead?

Thanks

It depends on what your need to do, but often times setting a spline's interpolation mode to Bezier, then setting the Bezier handles of the control points gives the most flexible solution:
See CurvySplineSegment.HandlesIn and similar, and CurvySpline.Interpolation
In general, whatever you want to do via code, do it first via the editor, and see if you get the expected result. Rotating a control point via editor will not get the result you expect (or at least what I understand is your expectation)

What seems to get the result I want is by drawing a spline in the editor but I can't get any result other than linear using the .Add() method, the HandlesIn are a way to do this but I'm having a hard time calculating the correct values, so i'm wondering. Is there a way to access the Draw Spline methods at runtime?
Reply
#5
The code used to draw spline from the editor uses the InsertAfter method, which is the same used in the Add.
If you want to check the editor spline drawing code, you will find it at TBDrawControlPoints.addCP (private method)
If you want to see an example of runtime drawing of splines, you can find one in the script used in example scene 51, InfiniteTrack.addTrackCP (private method)
Let me know if you managed to find what was wrong with your code using the Add() method
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
  Autogenerate bezier curve with a given direction AnAsianPanda 3 261 08-06-2021, 09:08 AM
Last Post: _Aka_
  Questions about Generator: mesh/objects within spline, snap to control point dartboard 5 808 06-09-2021, 12:42 PM
Last Post: _Aka_
  get a point on the curve a distance away from another fortune53 1 510 03-31-2021, 07:46 AM
Last Post: _Aka_
  Get nearest point problem Lupp_ 15 2,383 03-06-2021, 12:24 PM
Last Post: _Aka_

Forum Jump: