0

With only 1 dimension, you want to get to position X and stop there. you have a maximum acceleration A you can apply yourself; each frame you choose what direction to accelerate.

So if you have a velocity V, and want to stop at position X as fast as possible, how much of your maximum acceleration A do you apply yourself?

(If you are far away, you apply your maximum acceleration, but when you are close, you start braking. So based on your velocity and remaing distance, you need to decide when you begin to brake.)

ziggystar
  • 28,410
  • 9
  • 72
  • 124
user2154768
  • 890
  • 3
  • 8
  • 16

2 Answers2

1

The governing equation is x = v t + 0.5 a t^2 where x is distance, v is velocity, t is time, and a is acceleration in compatible units.

With no other constraints, in order to minimize your travel time, you will always apply maximum acceleration: Accelerate in the direction of the goal until you are halfway there, then accelerate in the direction of the origin until you stop.

If you have a maximum velocity, accelerate until you reach that maximum velocity, which will happen at some distance X away from the origin. When you are distance X away from the goal, accelerate back toward the origin.

Novak
  • 4,687
  • 2
  • 26
  • 64
  • 1
    Keep in mind that the equation means: 'x = v0 t + 0.5 a t^2', in which 'a' has to be constant and 'v0' is the starting velocity. Your strategy would work (50/50 acceleration/deceleration) if you would be standing still at your starting position. If you would be moving at the start you would have to decelerate (aka suicide burn with rockets) when the distance to the required position 'dx == 0.5 v^2 / a'. However I'm assuming that you are updating the position in an iterative manner. – fibonatic Apr 26 '13 at 16:50
0

Just dropping in with the answer to a more advanced version of this question I solved lately. You have v_0 at x_0, and want to reach position X, and have velocity V when reaching there. Acceleration is applied each small time step, e.g. 60 times per second.

So using the equation of motion x = v t + 0.5 a t^2, solve it for t with positive/negative acceleration applied, to see how fast one can reach x, regardless of end speed.

Also calculate how long it would take to reach V by applying the positive or negative acceleration. Whichever t is the highest, is the positive or negative acceleration to apply.

This causes objects to smoothly follow pahts such as sin(x), and if they are thrown off, they will elegantly slide back into it.

user2154768
  • 890
  • 3
  • 8
  • 16