Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spline object follow another Object
Hi there,
I'm just starting out with the tool and was wondering if you guys could give me just a quick hint in the right direction for my specific usecase - if possible at all.

I want an object to move along a spline and this object should follow another object only in forward direction. Meaning the spline object stays on the track, the object to follow can move in every direction but when it moves forward/backward, the object should move with it (hope that makes sense).

I used another spline tool before and coded a solution with some fency triangle math. 
So in case there is something in that regard build-in that may help me, please let me know. Otherwise I'm fine too, no problem! (The main reason for me switching the tool is actually that the other tool does not snap the spline points on the terrain properly which is highly annoying and time consuming)

Thanks in any case and best regards.

Assuming object A is following object B, here is a bit of code (from the top of my head, might not compile) that would keep A 50m behind B:

float bTF = yourSpline.GetNearestTF(B.transform.position, Space.World);
float bDistance = yourSpline.TfToDistance(bTF);
A.transform.position = yourSpline.InterpolateByDistance(bDistance - 50);

You can keep track of bTF or bDistance from the previous frame to distinguish if B is moving forward or backward.
Otherwise, when it comes to ready made components, Spline Controller is the one you will probably need the most.

Did this help?

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.
Thanks for the idea, will have a deeper look into it!

Possibly Related Threads…
Thread Author Replies Views Last Post
  Left-right movement, and spline follow shihaya 3 6 07-12-2024, 12:50 PM
Last Post: _Aka_
  How to start volume spots at the end of spline instead of front j95677 1 5 07-07-2024, 04:58 AM
Last Post: _Aka_
  How to get length starting from one spline to connected nth spline Dragon-3623 1 2 05-14-2024, 04:52 PM
Last Post: _Aka_
  Additional offset to Follow behaviour Ayyappa 3 13 04-30-2024, 01:35 PM
Last Post: _Aka_

Forum Jump: