After some experimenting I parented an empty (HeadCam) to the character's neck. This snippet allow rotation of the head synchronously to the CardboardHead/Camera.
void LateUpdate() {
neckBone.transform.rotation = Camera.transform.rotation * Quaternion.Euler( 0,0,-90);
Camera.transform.position = HeadCam.transform.position;
}
The character's arms shouldn't move when only the head rotates as long in the range -60° to 60° after that I would like to move the whole character with the arms still visible. The following method works as long the character isn't rotated by more than 180° after that the characters flips by 180° how could I achieve constant rotation?
void LateUpdate() {
Quaternion camRot = Camera.transform.rotation * Quaternion.Euler( 0,0,-90);
neckBone.transform.rotation = camRot;
float yrot = camRot.eulerAngles.y;
float ydelta = 0;
if ( yrot < 300f && yrot > 180 ) {
ydelta = yrot - 300f;
}
if ( yrot > 60f && yrot < 180 ) {
ydelta = yrot - 60;
}
playerObj.transform.rotation = Quaternion.Euler(0, ydelta, 0);
Camera.transform.position = HeadCam.transform.position;
}
A java applet for testing the algorithm standalone: https://github.com/3dbug/blender/blob/master/HeadCamRot.java