# Calculating bezier path when target is moving. (And calculate total travel time)

As a response to another question I asked here (https://math.stackexchange.com/questions/945593/2d-spaceship-movement-eta) someone suggested to use a bezier curve. This is not answering the question, but it can provide the effect I am looking for.

Scenario: I have a spaceship, which can be already moving, or standing still. I want to give it a point, and it will have to move towards this point in a natural way (the way natural born spaceships would do :) ). Using a bezier, with p1 and p4 being the source/target location, and p2 being related to the initial speed/direction of the ship and p3 being equal to p4, I have a pretty nice effect.

However, I want difficult things :)

I want the target to be able to be moving when my object is traveling towards it. I'm wondering if anyone has an idea on how to handle this.

ALSO: Beziers are calculated with an input value between 0 and 1 (eg. the time traveled). This means I need to know the total travel time beforehand. Can someone help me with this calculation aswell?

My idea so far:

1. Approximate the beziers length.
2. Using the start speed, a max-speed, acceleration speed and deceleration speed, calculate the time it would take to travel this distance in a straight line.

No idea how to do nr 2 though, or if it's even a good idea :) (bad at maths:P)

Hope someone can help..thanks in advance!

It sounds like you have code that works when the target point is stationary. If the target is moving, it just means that you have to keep re-executing that code repeatedly, with different inputs. So, pick some time interval, $\delta$. At times $t=0$, $t=\delta$, $t=2\delta$, ... run your original code. In each execution, the inputs to that code will change, but that's ok. Specifically, at any given time, the inputs will the current position and velocity of the spaceship (calculated from the previous Bézier curve) and the new target point. The spaceship won't jump, because it's traveling along a sequence of Bézier curves that are smoothly joined end to end.