- Home /
How to control an animation by touch position along a path?
I have a gameobject that I want to animate along a specific path/curve but the animation should be controlled by mouse/touch position. So when I touch/click on the gameobject and move the finger/mouse on the path (or maybe its easier to just move down) the gameobject should follow the defined path. I like iTween, but I think it is not possible to find a solution using it here, right?
thnx!
Is it a linear curve (made of small straight lines) or true mathematical curve? If mathematical, then what type? (Bezier, cubic spline etc...)?
its not defined yet but it may be any of these types.
Answer by Sajidfarooq · Aug 19, 2013 at 08:41 AM
If it is made of multiple small line segments, then this is how you would do it:
T = location of touch/tap.
Iterate through each line segment.
Find the closest point on each line segment to P.
From all the closest-points, choose the one that is closest to T. Lets call it CP.
Place your object at CP.
If you are using a mathematical curve, then you can find the closest point mathematically. The method will depend on the curve.
If you found this answer helpful, you ought to mark it as answered so others that have the same question can tell that this question was answered.