I am looking for a way to have the camera fallow the player while staying on a path. Think of a track camera where the camera can move forward and backward along the track but can not leave the track. The Spline Controller script is close but I need the camera to fallow the players movement instead moving on its own. The 3d Sonic games have this kind of camera motion. Any suggestions on how to do this?
I think you need a way to find the closest point on the track curve to a given point in space (you would basically find the point on the track closest to the player and then move the camera there). Unfortunately, this isn’t very easy to do for a freeform curve like a spline. However, if you can get away with something simpler, like an arc of a circle, then it is pretty straightforward.
If you really do need a freeform curve, then the type of spline implemented by SplineController is not ideal. Much better is the type of curve that approximates its control points (as if there were a jagged line drawn between the control points and the curve smoothes out that line). You get this effect with B-Splines (eg, see this thread) but better still are Bezier curves. The basic approach is to find the closest point to the player on each segment of the jagged line and then choose the closest overall. This identifies a particular section of curve. It is then just a matter of starting in the middle of that curve section and gradually sliding in whichever direction gets closest to the player. Easier said than done, though!