Mathematical, nautical steering problem

This is a discussion on Mathematical, nautical steering problem within the Game Programming forums, part of the General Programming Boards category; Hi all, I have a problem (isn't that obvious?) I am making a game which involves surface ships (a.k.a boats) ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    32

    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)
    current heading
    target heading

    THANK YOU!

  2. #2
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    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.
    Illusion and reality become impartiality and confidence.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    32

    Hey

    Thanx for replying my friend...
    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. #4
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    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. #5
    Registered User
    Join Date
    May 2006
    Posts
    32

    Of course

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

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    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
    DavT
    -----------------------------------------------

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    32

    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!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. Steering Algorithm Problem
    By Warlax in forum Game Programming
    Replies: 2
    Last Post: 10-17-2006, 12:00 PM
  4. help with mathematical problem in C
    By feelseez in forum C Programming
    Replies: 3
    Last Post: 09-10-2006, 11:44 AM
  5. Mathematical problem
    By Warlax in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2006, 02:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21