further modified it and removed some glitches. try playing with it, every click will change the x direction.