- Home /

# Move from A to B using parabola (with or without iTween)

Hi friends, I want to be able to move something from point A to B using Parabola. I have tried several things but it is not working and I was thinking that perhaps iTween would help but I have no idea where to start with that. I was wondering if there is someone who can help me either with or without iTween to achieve that.

The movement has to be in game, meaning that I select a gameobject (get its transform A) and click somewhere else B to move.

Thanks for your time.

**Answer** by IvovdMarel
·
Jun 08, 2018 at 07:41 AM

Although I'm never opposed to using math, the AnimationCurve in Unity might be the better/easier/more customizable solution here. Untested code:

```
public AnimationCurve curve;
public Vector3 end;
Vector3 start;
float time;
void Start () {
start = transform.position;
}
void Update () {
time += Time.deltaTime;
Vector3 pos = Vector3.Lerp(start, end, time);
pos.y += curve.Evaluate(time);
transform.position = pos;
}
```

Thank you on this I have movement clearly from a to b but there is something wrong with the curve cause in the beginning it starts to increase like a curve it reaches a certain height but then continues almost at the same height without ending at intended on the destination point. I wonder what is wrong with it.

The curve needs to go from 0,0 to 1,0 in the curve-editor to reach the destination.

Whaaat Ivo!? I know this might not be the best place but, hi! It is such a surprise to find you here! (Although maybe not really haha) I don't know if you remember me. Anyways I just wanted to say hi.

Have a great day!

**Answer** by jim3878
·
Jun 08, 2018 at 07:36 AM

good day.

this question can divided into x_move and y_move.

x_move is easier than y_move, if we don't care about air resistance.

```
float target_X = a.x + (b.x - a.x) * time;
```

For simplicity, time is a variable between 0 and 1. 0 = begin time. 1=end time. time=(Time.time-beginTime)/duration.

Secondly, let's look y_move.

Assume a.y is not equal to b.y.

We need to calculate the highest point of this parabola.

```
float maxHeigh = (a.y + b.y) / 2 + heigh;
```

"heigh" is a input value that determine delta Y of parabola.

Then, we can calculate move_Y

```
float target_Y = a.y + ((b.y - a.y)) * time + heigh * (1-(Mathf.Abs(0.5f - time) / 0.5f) * (Mathf.Abs(0.5f - time) / 0.5f));
```

Full Script:

```
public class Parabola
{
float heigh;
public Parabola(float heigh)
{
this.heigh = heigh;
}
public void Move(Transform target, Vector3 a, Vector3 b, float time)
{
float target_X = a.x + (b.x - a.x) * time;
float maxHeigh = (a.y + b.y) / 2 + heigh;
float target_Y = a.y + ((b.y - a.y)) * time + heigh * (1-(Mathf.Abs(0.5f - time) / 0.5f) * (Mathf.Abs(0.5f - time) / 0.5f));
target.position = new Vector3(target_X, target_Y);
}
}
```

test code:

```
public class ThrowTest : MonoBehaviour
{
public Transform a, b;
public float duration;
Parabola p;
Vector3 startPos;
float speedX, speedY;
float preTime;
void Start()
{
preTime = Time.time;
startPos = a.position;
p = new Parabola(5);
}
// Update is called once per frame
void Update()
{
if (((Time.time - preTime) / duration) <= 1)
p.Move(a, startPos, b.position, (Time.time - preTime) / duration);
}
}
```

Hi and thank you for your effort in helping me. I am trying your scripts but I get a warning that maxHeigh is not used and nothing happens, I see no movement.

sorry ,forget maxHeight,it is useless in this code. wold you check your inspect of ThrowTest? Transform a is your target item,and transform b is your destination.

There is not movement from A to B I suspect something is wrong with preTime , speedX, speedY are not used...

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.