Add force along a path

Hi!

I can’t seem to figure out a way to push an object along a path using AddForce. My goal is to only limit the players x axis along a spline, and keep the y and z axis free for jumping and going forward/backwards using AddForce.

I’ve seen some good examples out there like itween and spline walker, but these only reposition the object, and does not use physics to create movement.

Does anyone know how to achieve this effect?

EDIT:
During my testing I’ve made use of a script that I found on this site: Curves and Splines, a Unity C# Tutorial
Maybe I can make this work if I can calculate the closest point to the player on the Bezier Spline. Does anyone know what piece of code I would need for this?

Thanks!

I think I have an idea how I would approach that.

every frame the obj has a position, he calculate his position comparing to the spline and move another step.
so if i look of each step… there is the middle of the object and the middle of the spline.
if the spline is straight the middles are merged and you move forward.
in fact you always move forward.
diff is when the middles that you are handling to next step are not merged - same direction and position.
in this case I would calculate the difference in rotation and movement and add force and rotation towards potting the obj middle on the spline middle.

that’s my rough idea

40496-untitled.png