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
  Removing the objects behind an object alms94 6 5 12-06-2023, 09:31 PM
Last Post: _Aka_
  Curvy discards Input Spline Range VoltDriver 3 3 11-28-2023, 07:14 PM
Last Post: _Aka_
  Guide to custom placing stuff on spline Lupos 15 37 11-27-2023, 12:51 PM
Last Post: _Aka_
  Get spline from generated mesh beartrox 1 2 11-27-2023, 12:30 PM
Last Post: _Aka_

Forum Jump: