# What is the best approach for a moving path curve?

Hello fellow developers,

I would like to know what is the best and easy solution for a situation like this.

Concept: In my game, 3 types of fruit will be thrown by the character from point A to Point B. Each fruit will follow a curve way, problem is the fruit will have the physics as the character will throw the fruit from slingshot and once after thrown, fruit will follow a path. Currently, I have implemented the slingshot system and the fruits are thrown.

Between, the character will move up and down so the fruit throw position will also change.

It is a 2D Game

Problem:

1.How to make the fruit seamlessly follow the specified curve, once thrown from the slingshot? as explained above, the player position will move up and down, so is it possible to update the fruit path with smooth looking force and physics?

Is it possible to use spline curve? If so how to maintain the gravity and force? It would be great if someone can show direction. Thanks in advance.

You should try Catmull Rom algorithm:

http://www.mvps.org/directx/articles/catmull/

Equation goes as such in 2D:

``````public static Vector2 CatmullRomTangent(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, float t)
{
return 0.5f * ((-p1 + p3) + 2f * (2f * p1 - 5f * p2 + 4f * p3 - p4) * t + 3f *
(-p1 + 3f * p2 - 3f * p3 + p4) * Mathf.Pow(t, 2f));
}
``````

You define discrete points on your curve and it will define the movement naturally. The last parameter t is how accurate you want the curve. The higher t, the more expensive your curve but the more precise as well.

Since the equation takes A,B,C and D but it returns the path between B and C (look at explanation in the link) the first and last computation will get Vector2.zero for the first parameter (entry point) and for the last parameter (exit point).

For the rest you just pass all values in a array and use a for loop.