Sign in to follow this  
alwekyerp

An algorithm for steering a spaceship?

Recommended Posts

alwekyerp    133
I apologize in advance as I'm sure this question is answered somewhere, but I haven't been able to find it. I am making a space fighter game and I can't figure out a way to let the AI know how to steer to hit a waypoint. My current system is just to find the angle to the destination and fly the ship full tilt while turning to face the point. However this leads to the ship sliding right past the waypoint and eventually going into orbit. From flying a ship myself I see that the correct thing to do is to tell the AI to turn further then it needs to go, but I don't know how much to oversteer. Also, I need to be able to recognize situations where the ship is just going too fast and needs to slow down. It's worth noting that in order to make this game playable I have built in a magic "space friction" that opposes velocity not in the direction the ship is facing. This cuts down on the sliding, but does not stop it completely. Also, my physics engine is complete enough so I have access to all the velocities, forces, torqus, masses etc. I'm pretty sure I have all the numbers I need, I just have no idea how to combine them. For a more detailed version of the question (complete with stunning MS Paint diagrams) please check out: http://www.jameswells.net/turning.html Thanks in Advance.

Share this post


Link to post
Share on other sites
oliii    2196
something you can try, a "look ahead". Basically, calculate the state of the spaceship (postion, speed, orientation), say 1 seconds forward in time. Then calculate the inputs from that state, not from your current state. It should be quite quick to test, and you'll be surprised by the results.

Equally, apply the look ahead to the target. so, if it's a missile, calculate the missile state 1 seconds forward, and the target as well.

EDIT : make it one second.

Share this post


Link to post
Share on other sites
oliii    2196
alternatively, you can have a look at [google] Boids and Steering Behaviour. Very cool automated, navigation for A.I.

http://www.red3d.com/cwr/steer/gdc99/

Share this post


Link to post
Share on other sites
alwekyerp    133
Thanks so much for taking the time answer. I'll give the simple option a try first :) If it turns out to be that simple I'll kick myself, but as long as it gets finished I'm happy. Thanks again.

Share this post


Link to post
Share on other sites
bit64    218
Just choose a diameter around the waypoint. If your ship intersects with this diameter then cut the engines, turn your nose and coast into the waypoint.

Alternately, you could shoot for a different waypoint that is between your original position and the real waypoint. You can judge this distance by your current velocity and your distance away from the real waypoint.

Share this post


Link to post
Share on other sites
arithma    226
I haven't checked that link yet but have an idea anyway.
First of all it is very bad to pursuit the target 1 sec after it's current location (tried it).. The result of such AI is a space ship orbiting about a distance from its target (which is worse than it was)..

An alternative is to make it pursuit (orient it to) the target after a time t. This time t is collision time approximation. One simple approximation is calculating the distance between the target and yourself (ship, missile, etc) and divide it over some value.. You can even make your own robust approximation by giving it an analytic vectorial thought!

HAVE FUN!

Share this post


Link to post
Share on other sites
kaysik    382
If you've got the steering going already all you need is to vary the thrust! Simply scale the thrust based on the angle needed to turn and the distance you are from the target.

Make the ship fly slow if your close to your target or have a long way to turn. If your far away from your target and are facing it then max thrust. A few if() statements and scaling calculations should have you going in no time with a minimum of effort or changes to your code.

Share this post


Link to post
Share on other sites
oliii    2196
it's the relation between speed and distance, so the time it takes to reach the target, but like any interception algorithm, you need to be careful when the distance is small anyway. But that should cure the oversteer and understeer in a quick and simple way.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If you want an exact solutin for your "intercept" time you need strong math skills because there are some differential equations to be solved. But you can simplify your model: you can add a small force to your ship to compensate for the unwanted drift (of course when you're heading to the waypoint) so, in a few seconds you'll loose the drift. It's something like a "custom" friction on the unwanted drift. (this one worked for me).
Also your stearing speed should decrease (or even reverse) when you approach you're approaching the desired angle. If the stearing speed is linearly accelerated is a simple equation to find the stop time.
The way point should be far enough so the ship will have time to adjust the trajectory otherwise you may want to reduce speed (or even reverse).
This way you'll be able to orient the ship, but perhaps you'll have other problems when you reach a waypoint, because the ship will pass trough the waypoint and then it will reorient for the next waypoint. You may want to start reorienting prior reaching the waypoint.
In this case an easy solution is precalculation (or testing :) ) because you can presume your ship will move at max speed so, you should find a "good" "orient distance".

Hope this helps

c0mas.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this