# Thread: Mathematical, nautical steering problem

1. ## Mathematical, nautical steering problem

Hi all,
I have a problem (isn't that obvious?)

I am making a game which involves surface ships (a.k.a boats) and am delving deeply into the entire basic engine right now.

Dealing with the steering AI is a real problem.
I guess there's much more to courses and speeds than you think!

I have one problem though...

supposed you have a vessel which gets an input of a destination (x and y). this vessel has:

a constant top speed,
acceleration/decelration rate (same value) and a
"turn per second" which is how much the ship can change it's heading right or left per each second.

now my problems arises when i give my vessel a destination which is too close and too far to the right or left... it begins spinning around in a circle and never reaches it's destination, this is due to the fact that according to the algorithm... while the destination has not been reached... the ship is set to accelarate to top speed and keep that speed... so the ship actualy turns as much as it can, but it turns to slowly and keeps overshooting the target... am i being clear?

basically... I need an algorithm, or mathematical function that would yield the correct speed that the ship's supposed to reach in order to get to the destination as fast as possible... i think it will have something to do with circles... but I don't know.

again, these are my ship's variables:

current x
current y
destination x
destination y
acceleration/deceleration (constant)
current speed
target speed
top speed (constant)

THANK YOU!

2. At any point in time the ship has two circles to either side that it can't turn to, right? All you have to do is calculate (or simulate and store, depending on how accurate your physics model is) what those are and test if the destination point is inside them. Then you could switch to another state that avoids the destination or something until you can get back into a regular move state.

3. ## Hey

but how would you depict those two circles?
I need a radius basicaly... and then I know the circles' centers would be off that radius to the exact right and left... meaning 90 degrees off of the vessel's course... i think that's about right.
I still need to find the radius though...
i'm pretty sure it's a product of the vessels speed/sec devided by it's maximum turning per second... but I am not sure to just how much... think about it... the larger the speed or the smaller the turning ability... the bigger that "no turn into without slowing down" circle would get.

Thanx bro

4. Which is exactly what is supposed to happen.

You can't steer a real boat at max speed to an object that is inside of the boat's max turn radius at full speed. It will circle the object. You must slow down. You could do this:

Code:
```if (DistToObject<some_value && Ship.state == some_flag)
{
Ship.speed-=speed_decrease_value*fFrameTimeDelta;

if (Ship.speed<dock_speed)
{
Ship.speed=dock_speed;
Ship.state=some_other_flag;
}
}```

5. ## Of course

but... what is that distance from the object that under it, I will sow down?

6. If we ignore the current then your minimum turning circle will be of radius
r = speed / max_rate_of_turn
where r is in m, speed is in m/s and max_rate_of_turn is in rad/s

If the target is distance d away at a bearing (relative to your current direction of travel) a, then the fastest that you can go in order to get to the target can be calculated quite easily if you know a bit about trig as;

speedMax = (d * max_rate_of_turn) / (2 * abs(sin(a)))

so if speed > speedMax the you need to slow down

Introducing a current and wind etc. will make life more difficult - but you'll probably find
that you can ignore its effect if the speed of the current is much less than the speed of
the boat - experiment a bit.

Dav

7. ## thanx

that helped... i used the formula you presented to calculate the radius

and if distance to target destination is equal or lesser to radius the new target speed to be achieved is turn speed * d.

you rule!