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.

The subject says it all. I am making a 2d space game with newtonian physics and I need pointers on how to write an autopilot for it. The requirements are best explained by an example.

There is a target object which has speed and position vectors and there is a spaceship that is controlled by the autopilot. This spaceship also has speed, position and maximum acceleration. The autopilot needs to control the ship so that it either collides with the target or intercepts the target with matching speed and position.

Could someone give me some pointers how to achieve this behavior or perhaps even a ready implementation? I am sure someone has written something like this before and there is no point in reinventing the wheel.

share|improve this question
3  
The google keywords are "steering agent" –  Maik Semder Nov 7 '12 at 21:45

3 Answers 3

You will probably find what you're looking for here:

Steering Behaviors For Autonomous Characters

Maybe in this article:

Steering behaviors (full article)

share|improve this answer

Many of the currently available steer libraries are based on either OpenSteer or Programming AI by Example and have one fatal flaw: they rely on forward-facing physics which are out-of-the-box incompatible with physics libraries such as Box2d.

To illustrate the problem: in almost every single one of the steering examples, the direction of the agent, is the same as its force. This, however, doesn't hold true with physics libraries, where the force of the object can be different to the direction the object is actually facing.

Solving this can be fairly non-trivial. However,there is a video that seems to be doing something similar related to the book "The Nature Of Code". In the book, the implementation has been left as an excercise (6.21), unfortunately.

Trivial way to handle this is to cheat, and adjust your agents graphics heading independently of physics, but this seem like a sub-optimal solution to me. What about situations where you want to preserve non-forward facing physics of the physics library, but yet be able to steer the craft using autonomous agents?

share|improve this answer

In case you decided to write your own autopilot, I would always start by asking myself the question: What would I do in that situation? How would I plan my course, what maneuvers would I take? Surely you have mastered the task multiple times yourself. What steps did you take to arrive at your destination?

I know it still will be a pretty sophisticated autopilot. I would break it into smaller problems, i.e. a simple autopilot for making a course correction, one to kill rotation, one to come to a complete halt etc... Then later I would write more sophisticated ones that rely on the more simple ones - to automatically go from orbit of planet A to orbit of planet B, or one to intercept another ship etc...

I have thought about writing my own game for years now, and I think eventually I will have to face these problems myself...

share|improve this answer
1  
Hello and welcome to GD. You are answering old question with an answer, that is pretty much a collection of thoughts and not really an answer. This question does not have one good answer yet, so if you really know about this topic, try to add more "How to do it" information to your answer. –  Katu Jul 23 '13 at 5:18

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.