Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Look at next point
#1
Hi,

I need to place a point further on the spline.

So, I have an object that is moving along the spline and I'd like to dynmically place another object in front of it by 'x' units/length that is also following the curve.

How can I achieve that ?

Thanks,
Reply
#2
Hi,

CurvySpline.InterpolateByDistance allows you to get a point on a spline that is at a specific distance. Please take a look at the CurvySpline class, since it has various methods that should help you reach your goal. For example: TFToDistance, DistanceToTF, GetNearestPointTF, etc...
Also take a look at example scenes, for example 05_NearestPoint.unity, to see examples of usage of these methods.

Hope this helped.
Have a nice day
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
(11-01-2018, 11:10 AM)_Aka_ Wrote: Hi,

CurvySpline.InterpolateByDistance allows you to get a point on a spline that is at a specific distance. Please take a look at the CurvySpline class, since it has various methods that should help you reach your goal. For example: TFToDistance, DistanceToTF, GetNearestPointTF, etc...
Also take a look at example scenes, for example 05_NearestPoint.unity, to see examples of usage of these methods.

Hope this helped.
Have a nice day

Thank for the help. I came to this solution which unfortunately doesn't work as expected :

NextPoint.transform.localPosition = splineController.Spline.InterpolateByDistance(splineController.Spline.Position)

I expected the NexPoint gameObject position to be exactly on the curve but it's offset...
Reply
#4
As explained in the documentation, splineController.Position can have different meanings depending on the value of PositionMode. Since I don't know what value PositionMode your controller has, I will use instead use AbsolutePosition which is independent from PositionMode's value.

CurvySpline.InterpolateByDistance returns the a local position, which means the position of the point in the local space of the spline. I guess that you read the documentation and are aware of this point, since you assigned NextPoint.transform.localPosition, but this is not how you use local positions. You should transform the position from the spline's local space to the global one, and then assign it to NextPoint.transform.position. To transform a local position to a global position, you use https://docs.unity3d.com/ScriptReference...Point.html

So the end result should be
var spline = splineController.Spline;
var localPosition = spline.InterpolateByDistance(splineController.AbsolutePosition);
NextPoint.transform.position = spline.transform.TransformPoint(localPosition);

I typed this code outside of an IDE, so it might have some minor typos.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(11-01-2018, 01:50 PM)_Aka_ Wrote: As explained in the documentation, splineController.Position can have different meanings depending on the value of PositionMode. Since I don't know what value PositionMode your controller has, I will use instead use AbsolutePosition which is independent from PositionMode's value.

CurvySpline.InterpolateByDistance returns the a local position, which means the position of the point in the local space of the spline. I guess that you read the documentation and are aware of this point, since you assigned NextPoint.transform.localPosition, but this is not how you use local positions. You should transform the position from the spline's local space to the global one, and then assign it to NextPoint.transform.position. To transform a local position to a global position, you use https://docs.unity3d.com/ScriptReference...Point.html

So the end result should be
var spline = splineController.Spline;
var localPosition = spline.InterpolateByDistance(splineController.AbsolutePosition);
NextPoint.transform.position = spline.transform.TransformPoint(localPosition);

I typed this code outside of an IDE, so it might have some minor typos.

works like a charm ! 

thanks
Reply
#6
You are welcome
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
  Generate path from point A to point B taking account of direction TheLogan 1 428 05-05-2018, 02:03 PM
Last Post: _Aka_
  Add control point along spline hoesterey 3 1,140 03-20-2018, 04:20 PM
Last Post: nomadigi
  Detecting if I'm in a "Connection" control point atomsinthevoid 1 602 01-28-2018, 12:21 AM
Last Post: _Aka_
  Closest Point on Spline (+Offset) to some World Position nomadigi 10 2,678 01-26-2018, 08:59 PM
Last Post: _Aka_

Forum Jump: