Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spline object follow another Object
#1
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.
Reply
#2
Hi

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Follow-Up are automatically changed to be "No Follow-Up" Chanon 2 13 06-19-2022, 04:24 AM
Last Post: Chanon
Brick Delete CurvySplineSegment from the start of a Spline causes UV's to change studentloan 5 6 06-14-2022, 03:14 PM
Last Post: _Aka_
  Obstacle Moving Along the spline Chanon 1 5 06-13-2022, 04:13 PM
Last Post: _Aka_
Information Common reasons why your spline gizmo is invisble _Aka_ 0 1 05-20-2022, 03:56 PM
Last Post: _Aka_

Forum Jump: