- 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;
}
```

**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);
}
}
```

### 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.

### Follow this Question

### Related Questions

using itween to move objects in the 6 degrees of freedom 1 Answer

using itween how can move gameobject smoothly in game? 1 Answer

iTween stop function not work on inactive object? 1 Answer

iTween issue 1 Answer

itween PutOnPath rotating 1 Answer