# 2D Boat controlling physics

I'm working on a top-down 2D boat game with Unity3D. I couldn't able to understand how to implement physics of rudder controlling. My physics knowledge is not enough to think how rudder dynamics work. How rudder dynamics works in water? Can you help me for finding a starting point for this?

Since I'm not able to think any solution for this, I can't provide an example code.

EDIT:

I'm trying to apply a force to rigidbody2D of the ship at the point of rudder with angle of the rudder. But I couldn't able to make something working

Sample Code

I draw a sketch. Red point is location of rudder. I'm trying to apply a force at that point with angle of rudder relative to ship heading on each Update. How can I do this?

• This is a very broad question. But it all depends on how complex you want your game mechanics to be. Do you want to take the flow of the water into consideration? Most games just rotate the ship at the press of a button, even without the ship moving. even assassin's creed 4: black flag, the pirate simulator, just rotates your ship when you move the left analog stick. And for a 2d top down game, i would aay that is probably the best way to go about it. – Peethor Jan 23 '15 at 23:26
• I want to build something as realistic as possible. I don't want to build something that simple with just rotating the ship. – MBraiN Jan 24 '15 at 0:09

The simplest, modestly realistic, model I can think of would be parameterized by the following:

• Mz The Turning Moment of the ship about the steering (ie Z or yaw) axis;
• L/2 The distance of the rudder from the turning axis, approximated as 1/2 the ship's length L;
• v The current linear velocity of the ship (relative to the water, not the land nearby, so take into account any current).;
• w The current rotational (yaw) velocity of the ship about the Z-axis, measured CCW in radians per second;
• p0,p1,p2 The constant, linear and quadratic coefficients respectively of angular friction (ie resistance to turning) for the water (these control how quickly the ship stops turning when the rudder returns to straight, and impose a limitation on how sharply the rudder can be turned before losing any effect.)
• A the area of the rudder;
• d the density of the water.
• theta the current rudder angle measured CCW from straight back in radians
• delta-t is your time interval.
• Cd is coefficient of increased drag due to a non-neutral rudder position.

Then the relevant equations of motion can be derived something like this:

1. Turning torque from rudder Tr == sin(theta) * A * v * d * L/2
2. Friction torque from water Tw == p0 + p1 * w + p2 * w^2
3. Net torque T == max(0, abs(Tr) - abs(Tw)) * sign(Tr)
4. w' == w + T / Mz
5. heading' == heading + (w' + w) * delta-t / 2
6. Drag on forward motion increases by Cd * abs(sin(theta)) * **A * v * d

I think I have the signs correct, but that can be corrected if necessary by multiplying T by -1 in either equation (3) or (4).

By playing around with the parameters you should even be able to get an appropriately different feel for larger vessels compared to smaller ones. You should also set a modest limit on how fast the rudder can be turned, and prevent it from being turned further once Tw exceeds Tr.

Setting p0 greater than zero will nicely model the fact that ship have no steerageway below a minimum speed.

Update

Calculation of Moments of Inertia - For ships of the same style but different sizes, the moment of inertia should vary linearly in the mass of the ship, and as the square of the length of the ship, as a first approximation.

Update 2:

• Added Equation (6) above and corresponding drag coefficient; and

• corrected equation (1) with additional factor L/2.

• Wow, thank you. I'm going to try to implement this in Unity3D. But it seems its going to be difficult :) – MBraiN Jan 26 '15 at 23:32
• @MBraiN: I am totally unfamiliar with Unity3D, so cannot help you there much, but am willing to assist in translating my answer and terminology into English. As a Physics Engine Unity3D should support everything I have described, but my terms may not be identical in all cases to Unity's. – Pieter Geerkens Jan 27 '15 at 3:11
• @PieterGeerkens do you know any library which have an implementations of those formulas? – mwweb Sep 17 '17 at 18:52

If the rudder turns left /, the boat turns left.

If the rudder turns right \, the boat turns right.

The more you turn the rudder, the greater the turn the boat takes. This assumes the rudder never turns 90+ degrees.

The / and \ assume the boat is facing up ^.

   ^
|  |
|  |
---
/   <---rudder

• At the same rate? That depends on the complexity of the dynamics. Because when you have a big, heavy ship, that's deep in the water with a relatively small rudder, the rudder's rotation is going to have less effect than if you put the same rudder on a small, light, and shallow ship. – Peethor Jan 23 '15 at 23:36
• @Peethor good point. Edited. I was trying to give a very high level answer, as he said he didn't know where to start. – Evorlor Jan 23 '15 at 23:37
• @Evorlor I'm trying to apply a force to rigidbody2D of the ship at the point of rudder with an angle. But I couldn't able to make something working. – MBraiN Jan 24 '15 at 15:18
• @MBraiN it appears you must be using Unity then. Please update your question with what you have tried including code. Then add the appropriate tags, such as the Unity tag. – Evorlor Jan 24 '15 at 15:19
• Update question. Not comments – Evorlor Jan 24 '15 at 15:21