Well, first of all you need a way to descrive such path.
I would use some spline curves like Bezier curves or Hermite Splines to describe the path, and let the button follow that path once pressed.
Unfortunately these curves are not available as is, you need to implement them.
If you are interested here you can find 2 nice Herman Tulleken's articles(fundamentals and some algorithms), that contains a basic bezier spline implementation for Unity3D too:
If you want to go another way you can define some points the button should pass through and interpolate position (and eventually orientation) of the object while updating its position.
You can interpolate
Vector3 position using Lerp or Slerp methods.
If you attach your script you should be able to see the Bezier curve drawn.
(Pay attention that your control and tangent points are coincident, so it will be always a straight line). Unity just let you draw such parametric curves, you have to evaluate it on your own.
The article I linked to you gives you the code. For example:
Vector3 CalculateBezierPoint(float t,
Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
float u = 1 – t;
float tt = t*t;
float uu = u*u;
float uuu = uu * u;
float ttt = tt * t;
Vector3 p = uuu * p0; //first term
p += 3 * uu * t * p1; //second term
p += 3 * u * tt * p2; //third term
p += ttt * p3; //fourth term
You can move a GameObject along the curve you can varying
t parameter inside your Update function. For example:
float time = 0f;
if (time < 1f)
time += Time.deltaTime;
transform .position = CalculateBezierPoint(time,startP, startT, endT, endP );
how could I clamp the coordinates so that the button only slide on the
curve, exactly where the touch is (without any delay)? I thought about
creating a list of 50 Vector2, and compare the x/y with the touch pos,
but it might be too heavy... Would you have any idea about that?
Well, the curve parameter domain is [0,1]. You could for example start recording a gesture when a touch is detected near the start control point.
Supposing you gesture length is [0,N], what you can to is to map the gesture interval domain to the curve one.