3
\$\begingroup\$

I'm working on a 3d space sim with AI agents flying ships through space. I am trying to get them to follow a waypoint path nicely, which involves figuring out how fast they can be travelling and still manage to pass through the waypoint.

Given a point in 3d space and an an agent that only travels forwards and has a given turning rate in radians / second and an acceleration rate, how can I find the maximum speed the ai can travel and still manage to face the point before overshooting it?

Can any math wizards lend a hand?

public class AIPilot { //relevant fields from my class
   float turnRate_radians;
   float acceleration;
   Transform transform;

  public float FindMaxSpeedToFace(Vector3 goal) {
    //trying to fill the body of this method
  }  
}
\$\endgroup\$
  • \$\begingroup\$ "acceleration rate in meters / second" you mean velocity? acceleration is measured in ( m / (s*s) ) \$\endgroup\$ – dnk drone.vs.drones Sep 15 '15 at 8:05
  • \$\begingroup\$ Is it assumed that the ship starts with zero velocity? What do you exactly mean by overshooting - should the ship have zero velocity when reaching the end-point? I fear that there might be no analytical solution for that. \$\endgroup\$ – Wumpf Sep 15 '15 at 18:09
  • \$\begingroup\$ We can assume the ships start with zero velocity, they don't but once I find a maximum speed I can figure out if I can hit that speed based on my current velocity. What I mean about overshooting is that the agent should not miss the target and need to circle back around. Arriving is not the goal here but I know that for some points in space a near zero speed will be the maximum speed to reach a point. \$\endgroup\$ – weichsem Sep 15 '15 at 19:26
1
\$\begingroup\$

Is it critical that your function be "What is the max speed"? Finding a closed-form calculation for that is a bit hairy.

It seems like a more useful/general-purpose function might be "Can I keep accelerating and still face the target point?"

You already know from your previous answer from zehelvion how to calculate whether you can reach a target given a your current velocity and max turn speed.

So, assuming each time step you are turning towards the target as fast as you can, then you can also calculate whether additional acceleration will make it impossible to face the target. If not, go ahead and accelerate.

The max speed you arrive at is your original answer, but now you maybe don't need it. :)

(I.e., using this approach your AI agent should arrive at the point as fast as possible given its physical constraints.)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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