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
  Curvy Line Renderer for UI Spline? gekido 1 1 7 hours ago
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 2 7 hours ago
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: