1
$\begingroup$

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!

$\endgroup$

1 Answer 1

1
$\begingroup$

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.

The Bézier curves only give you path of the spaceship; you should control its speed using independent calculations.

$\endgroup$
2
  • $\begingroup$ Assuming you mean recalculating the bezier based on the original start position and the new target location: Imagine the object moving in a straight line towards the target. If the target then moves (fast) parallel to the object's movement, the object will get a sidewards movement. Also, if the target moves really fast, it will also accelerate the object's movement, since the bezier will be stretched. $\endgroup$
    – Jasper
    Sep 25, 2014 at 13:01
  • $\begingroup$ Reading back, I think I'm not clear: I mean: if you calculate a second bezier, and follow thatone instead, the object can "jump" through space, from one bezier line to another, not overlapping bezier line. If I calculate it again using the objects new position, and do that every frame, the object will not really feel the effects of being in a bezier. It will keep the same speed. $\endgroup$
    – Jasper
    Sep 25, 2014 at 13:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .