Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Ok so consider we have a vehicle like the one I described in my answer to this question, with a 2D position, velocity, angular velocity, and drag/friction. It can accelerate and break by a variable amount, but not stop dead instantly or reach top speed instantly. How can I make it move to a particular point and stop - in the fastest time possible - without overshooting or oscillating?

I was thinking something like:

  • turn towards target position.
  • accelerate
  • look 1 tick ahead, asking "If I applied the breaks next tick, would I overshoot the target?"
  • If it would overshoot, apply the breaks now by some amount.

I'm sure this is a solved problem and there is a probably a better method than the one I described.

share|improve this question

4 Answers 4

Using calculus, if you know your velocity and maximum deceleration rate then you can know your minimum stopping distance. With that in mind, you can know exactly when you need to apply the brakes (rounding/quantisation errors aside) to stop at a certain point.

Now, hopefully someone better at mathematics than me will post the actual formula...

share|improve this answer
2  
finalPositionDelta = -0.5 * sqr(currentSpeed) / maximumDeceleration However this assumes that your deceleration is a constant, which depending on the depth of your simulation may not be the case. I'd go with Ranieri's solution. (whoops sorry it's DIV deceleration, not mul) –  tenpn Aug 20 '10 at 11:18
    
Yeah, this method is still useful even if you frame it as a control systems problem, because understanding the gradients involved should help avoid instability or oscillation in the error measurement. –  Kylotan Aug 23 '10 at 14:56

It's a control problem. You need to vary your inputs proportionally to some kind of "error" measure, like the distance to the target. See also the answers to this question.

Target Tracking: When to accelerate and decelerate a rotating turret?

share|improve this answer

Sometimes, in game development, you need to take shortcuts. The shortcut here is called an Impulse, which, physically speaking is a very large force applied in a very short time. Instead of integrating it over time, you just apply it to the parameter as a direct change: set velocity to 0.

The question is: do you want to use the shortcut or not?

share|improve this answer
1  
I'm not worried about taking shortcuts if it's invisible to the player, but if a vehicle could stop dead on the spot it would look very strange. –  Iain Aug 20 '10 at 18:37
1  
That is certainly true, however it helps to stop precisely at the point you want it to after a decelaration, thus avoiding complex calculation and having the divide your time step too many times. –  ADB Aug 21 '10 at 11:27

Steering Behaviors For Autonomous Characters. Check out seek and arrival.

share|improve this answer
    
Great for boids or space ships, but to apply them to vehicle physics you have to interpret the resulting vector, and you're back to the original problem again. –  tenpn Aug 20 '10 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.