Prevent character side movement in 2d side scroll

The side scroll project have only forward movement , and i like to make a game depending on this project like the trine game , but the problem is when the character face something like sphere it will get pushed in a side so he resume his normal forward path but he is pushed away from the 0 Y axe to something like 100 unit away from zero Y axe so how to prevent the character to move in Y axe even when he encounter such object that will slide him from his Y axe ?

thanks

Found it by help from unreal form thanks to him , called some thing like character movement constraint planner ,.