- Home /
object following a path, like train - railroad
Hi, what techniques can I use to make object follow a path? something like a train following railroad.
it must be able to follow strait lines, and curves as well.
speed by which gameobject will move will not be constant, it might accelerate or slow down.
I'm new to unity and don't know how to approach this.
only solutions I could think of were 1: animating path in 3d program, but then how do set speed in realtime? 2: adding kind of pinpoint objects, my car or whatever will move towards. but will it be possible to get exact form of path object this way? I could add pinpoints at the same locations where vertexes are on path object, basically a turning points of curve. but is there any function that can track in realtime which pinpoint is next and function that can calculate curve between last and next pinpoint?
Answer by Hellwalker · Apr 28, 2010 at 07:04 PM
http://www.unifycommunity.com/wiki/index.php?title=Spline_Controller
was the best easy solution I found, but speed and rotation proved tricky
Stuff got moved. Here is the updated link: http://wiki.unity3d.com/index.php?title=Spline_Controller
Answer by efge · Apr 01, 2010 at 12:40 PM
I would suggest solution 1 because when you want a train follow a railroad track you need the exact position and rotation of the individual objects.
Reference for Animation Curves
For changing the velocity there might be 3 solutions:
1. You could also use an animation curve.
2. Set Animation Events for specific frames. (also useful for signals or speed limits at stations)
3. Calculate the velocity depending on the pitch and roll of your game object.
Waypoint/Bezier examples can be found in the Unity forum.
I used railroad example, but my actual gameIdea is bit different.
I want to make curved track in 3d program, and I want gameobject to follow its path constantly, speed might change when player hits button or runs over some gameobject, kind of speedboost.
I will look into your links, thanks
Answer by Ricardo · Apr 01, 2010 at 11:09 AM
You want to look into:
- Pathfinding
- Steering
- Waypoints
Those topics will cover what you want to accomplish. Unity doesn't give a solution for any of these out of the box, but there are several available online. Read up on the articles for the tags I added to your question.
Answer by tyados · Apr 18, 2014 at 07:00 PM
I also came across curvy from fluffyunderware or something. I didn't try it yet but seems promising. iTween also seems to deliver something in regards of path finding, but the demos that i saw wasn't that "curve-y". I'll try a bit more and maybe update this answer.
Your answer
Follow this Question
Related Questions
Help with a simple AI 2 Answers
Pathfinding over a dynamically deforming mesh 0 Answers
How do I add more waypoints to a moving platform script. 1 Answer
Avoidance Behaviour 2 Answers
Steering an AI vehicle to a waypoint using float of -1 to 1? 1 Answer