Combining 2 Rotations: Global and Local

Here is the problem: ship on the sea (XY plane).Ship turns left right ok. When turning I want the ship to heel (rotate a little along the longitudinal axis).

Left right turning works ok with this code:

 var rotationVector = GameObject.Find ("SHIP").transform.rotation.eulerAngles;
    rotationVector.x = 0f;
    rotationVector.y = 0f;
    rotationVector.z =  rotationVector.z + 0.5f; //well , a function anyway
    GameObject.Find ("SHIP").transform.rotation = Quaternion.Euler(rotationVector);

If I try to add the second rotation on the Y axis (the heeling), the resultant rotation gets weird.

 var rotationVector = GameObject.Find ("SHIP").transform.rotation.eulerAngles;
    rotationVector.x = 0f;
    rotationVector.y = rotationVector.y+ 0.5f;
    rotationVector.z =  rotationVector.z + 0.5f;
    GameObject.Find ("SHIP").transform.rotation = Quaternion.Euler(rotationVector);

As far as I get it, the rotation is local, and heeling takes steering off the horizontal and the ship goes either airplane or submarine. I could make an Z adjustment each frame to compensate but I don’t get the heeling!
Tried 2 rotations stages, tried fist one then the other, variants from forums but I can’t get it working…

How to get the banking local and the turning global on the same object?

This is getting me bugnuts
Heelp!?!

It might be that the order of rotations is different than you expect. Try this (of flip the order to y/z quaternions):

GameObject.Find ("SHIP").transform.rotation = 
   Quaternion.Euler(new Vector3(0, rotY, 0)) * 
   Quaternion.Euler(new Vector3(0, 0, rotZ));

It turns out the solution was

 GameObject.Find ("SHIP5").transform.rotation = Quaternion.AngleAxis(rudder5, Vector3.forward)*Quaternion.AngleAxis(heel5, Vector3.up);

41188-steer-and-heel-done.jpg

Well, the angle changes from 0 to 360 and from 360 to 0 when passing 0 but that can be dealt with with a ton of IF’s for both rudder and heel angles.

For anyone having this problem, I’m attaching the whole code

[41190-turn-and-heel-code-solved.txt|41190]