What I’m creating is essentially the movement system used in Kibry 64, where the player can move left and right along a 2D path, but the space itself is 3D.
What I have set up to implement this is a series of nodes that are connected by bezier curves. Setting up the path is not the issue, however. (I have an image below if anybody is having trouble picturing what I’m saying)

What I’ve been doing to keep the player along the path is to set the fwd vector to the tangent along the curve (derivative of the bezier function, with how far the player is along the curve plugged in). The problem with this is that if the player overshoots a node due to his speed, he will still only adhere to the curve’s direction without being corrected onto the path. Needless to say he gets off base very quickly.
The other solution I thought of was to just keep track of 2D position in the script, and snap the player onto the curve. This will not work, though, because I am using a rigidbody for the player’s physics model, and setting the position manually will break the physics.
Quite a pickle, eh? I know it’s a bit of an unconventional problem, but I hope somebody will have the ingenuity and knowledge to set me in the right direction. Thanks!
You could try a simple P (proportional) controller: calculate the actual and the desired positions, and apply a force proportional to the error in order to fix the trajectory - something like this:
var desiredPos: Vector3;
var gain: float = 10.0;
var maxForce: float = 50.0;
function FixedUpdate(){
// calculate the error
var error: Vector3 = desiredPos - transform.position;
error.y = 0; // remove Y component if you want to keep physics gravity
// calculate the necessary force and clamp it to maxForce:
var force: Vector3 = Vector3.ClampMagnitude(error * gain, maxForce);
rigidbody.AddForce(force); // apply the force
}
Update desiredPosition each frame and the controller will try to move the rigidbody to it. You may have to adjust the factors gain and maxForce in order to achieve a more stable operation, but oscillations and overshooting may occur in a simple P controller . A more complete approach (a PID controller) can be found in the Bonus Script of this question: it implements a Proportional Integral Differential controller.
Can you calculate the world (3D) location as a function of the 1D distance from the beginning of the path?
Then you could simply advance “distance” as the player moves forward, and immediately calculate the position as
transform.position = GetPositionFromDistance(distance);