Transform Rotation - Maths Problem


I’m trying to figure out a rotation problem here.

My scene camera rotates by using my iOS gyro (on an X, Y, Z and W axis)- so basically, if I rotate my phone around my physical room, the game scene will also be ‘copying’ my rotations on the scene camera.

Now, what I have is a ‘hand’ model as a child, within the camera, so it rotates with the camera - so it looks like it never rotates to the viewer of the camera.

Hear me out - when I rotate the actual device sideways (Z axis), I want the hand model to always stay the correct way up. Let me do an illustration (It’s hard to explain):

^ This is what I WANT to happen. Right now - the hand just stays at the default orientation (But still moves with the camera, so its always in view, in front of the camera).

All thats changing my camera rotation is this:

rotFix = Quaternion(0,0,1,0);
var camRot : Quaternion = gyro.attitude * rotFix;
transform.localRotation = camRot;

Any ideas how I can achieve this with my hand? Thanks!

— EDIT —

A good example I found on the app store is a game called AR Zombies - When you hold the device and rotate around your actual room, the game moves with your rotation (This is already working fine). But, if you rotate your device sideways (left and right), notice how the character (weapon) is always dynamically at the bottom (it rotates with the device).

I believe you could achieve the effect you’re searching for by putting your hand on one layer and drawing it with a separate camera.

So you would have a new hand layer and a new camera. The camera would be set to just drawing that hand layer. Your main camera would be set to drawing everything but that hand–as well as set to depth only. Depth only being a clear flags option.

This is a common method for using elements in 3D space as GUI elements though it’s also a popular option for drawing hands and what not to the main camera so that is separate from that camera’s rotation in some respects.

The effect is that the hand is now constantly drawn to the screen in a static position while the rest of the world moves fine.

EDIT: I reread your question and understand it a bit better now. In which case I don’t believe what I typed above will be the solution you’re looking for–I will leave it up there as it is still tangentially related. You could always define the behavior of the hand in a script so that it mimicks the motion you want it to. It doesn’t have to be a child of your camera–which is the only way, save for a script, it would inherit the rotation of your camera.

If i got it right, you need to use Quaternion.Inverse:

yourHandTransform.rotation = Quaternion.Inverse(gyroRotation);

i dunno how gyro gives you rotation info, but i’m sure your get the point.