0
\$\begingroup\$

I am able to update velocity of my agent every 0.5 seconds. My agents max speed is 5f/s and max acceleration/deceleration is 2f/s.

I know how far away I am from the destination. How to determine current max velocity that my agent can go at the moment, to be able to decelerate to the destination (ending at velocity 0)? Since I am able to change velocity only twice per second and my max deceleration is 2f/s, I would image my agent arriving to the destination at max 2f/s velocity and then changing it to 0.

\$\endgroup\$
1
  • \$\begingroup\$ This previous Q&A is about the continuous case, but it may have useful leads for you. \$\endgroup\$
    – DMGregory
    Commented Feb 16 at 12:36

2 Answers 2

1
\$\begingroup\$

Just work backwards to set up a "glide path" are the closest points/maximum speeds you can get without overshooting:

If you arrive to the destination at max 2f/s velocity and then change it to 0,

0.5 seconds earlier you are 1 ft away changing from 4f/s to 2f/s,

1 second earlier you are 3 ft away changing from 5f/s (the max) to 4f/s,

More than 3 ft away you are at 5f/s.

So the glide path is:

Distance Max speed arrival Max speed departure
3 5 4
1 4 2
0 2 0

The idea is that when you get to a particular distance on a tick, you are are travelling at no more than the arrival speed, and at that distance you switch to the departure speed.

Taking your 5.4f example, if you were to travel at maximum speed if 5 f/second then you will be 5.4-2.5=2.9f away moving at 5, which is no good (faster and closer than specified by the glide path), so instead immediately reduce the speed to 4.8f/s, then after one tick you are 3f away and can reduce to 4f/s and stay on the glide path, so:

time distance speed
0.0 5.4 4.8
0.5 3.0 4.0
1.0 1.0 2.0
1.5 0.0 0.0

So it takes 3x0.5=1.5s to get to the stopping point (your solution in comments takes 2s by travelling slower).

\$\endgroup\$
4
  • \$\begingroup\$ Maybe I didnt understand correctly, but this doesnt work well when I am e.g. 5.4f away from destination. Because in this case, my maximum initial velocity is 3.6f and 1.8f. So by having the velocity closer to the destination lower, I was able to boost the following velocity. I dont really see how this example maps to your solution. \$\endgroup\$
    – Peter
    Commented Feb 19 at 15:47
  • \$\begingroup\$ @Peter I'm not sure where you get 3.6 and 1.8 from, but there is a problem with my solution - it assumes that the ticks happen at the 'right times'. I will think about this and edit my answer. \$\endgroup\$
    – MadMan
    Commented Feb 19 at 16:40
  • \$\begingroup\$ In the continuous case, you want start maximum deceleration as late as possible. The discrete case will be analogous to this, but the edge cases may be a bit trickier. \$\endgroup\$
    – MadMan
    Commented Feb 19 at 16:51
  • \$\begingroup\$ Well I simply though of a case where you are 5.4f away. The best solution for this if you want to maximise speed as far away from destination as possible, you can go up to 3.6f/s, and next second you will switch it to 1.8f, after that you will be at the destination and can switch velocity to 0. \$\endgroup\$
    – Peter
    Commented Feb 19 at 18:38
0
\$\begingroup\$

Dubre Den,

The max and assumed current speed(5) requires <3.0 max deceleration steps(-2 speed) to reach 0.

Since the update rate is twice per second, the exact solution should be apparent without calculus.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ If the solution is apparent, it would be helpful to write it down here in full. \$\endgroup\$
    – DMGregory
    Commented Feb 18 at 12:04

You must log in to answer this question.

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