Pitch yaw and roll question

Hi all,

Im trying to make some spaceship controls but im missing something (or a lot).

First of all, im not good with 3d math, I know I should be specially for what Im trying to do, but im still learning.

What I want to achieve here is a simple navigation control code but for some reason everything gets messed up as you can see in this video:

sometimes when I roll my ship 180 or 360 degrees the axis get inverted or when I make a loop the controls get very weird.
I made a very simple code for the navigation:
http://pastebin.com/xwkB0BXZ

When I look throughout the internet I either find 2d games or people asking about acceleration, or then its too much physics.
I just want really to be able to roll pitch and yaw without problems.

The first thing you might try is reversing the order of multiplication in this line:

wantedRotation = zQuaternion * xQuaternion * yQuaternion;

At that point I think you’ll be using the same axis order that Unity uses internally; if so, you could instead use Quaternion.Euler() or just assign the angles directly to the ‘eulerAngle’ field.

If that still doesn’t give you the results you’re after, it may be that it’s actually a 6DOF control scheme that you want. If so, that can easily be achieved using Transform.Rotate().

None of them worked. The same kind of problems in different situations.

The only thing that I havent tried is the 6DFO, I googled it and it seems to do what I want but never heard of it before.

“6DOF (six-degrees-of-freedom) refers to motion of a rigid body in three-dimensional space, namely the ability to move forward/backward, up/down, left/right (translation in three perpendicular axes) combined with rotation about three perpendicular axes (pitch, yaw, roll). As the movement along each of the three axes is independent of each other and independent of the rotation about any of these axes, the motion indeed has six degrees of freedom.”

That sounds just great im going to do some googling about it, kinda hard to find though, im looking at gamedev.net now.
If you have any tips where i can find some reference about it plz let me know.

Thanks! :wink:

There’s actually not much to it (not in this context at least). With the second argument left at its default value (‘Self’), Transform.Rotate() will apply the specified rotation in local space. So, to apply a local yaw rotation, you might write (untested):

transform.Rotate(Vector3.up * yawVelocity * Time.deltaTime);

Where ‘yawVelocity’ is a signed value that indicates both how fast the object is rotating about its local ‘up’ axis, and in which direction. (Pitch and roll would be handled similarly.)

Also for aesthetic reasons (just my 2 cents) I would move the pivot/rotation point further back towards the engine near the flight control area for a more realistic movement.