I finally came across this formula:
object.X+cos(angle(object.X,object.Y,touch.X,touch.Y))*clamp(distance(object.X,object.Y,touch.X,touch.Y)*cos(Angle(object.X,object.Y,touch.X,touch.Y)),0,256)
Not sure why, but I had to use cos(Angle(object.X,object.Y,touch.X,touch.Y)) on the y part. It would not work with sin.
Edit: nevermind
Same deal with angle()
Edit 2:
Fixed it with anglediff... sort of.