I have a child object which is always having different positions and rotations (thats my VR Headsets Eye-Gameobject) I cannot modify the position and rotation of that.
I want to set my view to a certain "startposition" and "startrotation" so the player always has the same view at the start of the game.
The childs local position is always set to some values. So I cannot unparent it. If I unparent it, I change his position.
now..
It works with the position.
Parent.transform.position = 2 * ParentStartPostion - Eye.localPosition;
^ This line of code here sets my parent object so that my Gameobject: "eye-camera" is where i want it to be.
For the rotation part, i would do following:
Eye.parent = null; //unparent the eye to the world
Parent.transform.position = Eye.position; //set my Parent to the same position as Eye
Eye.parent = transform; //parent it back. Local Eye should be 0.0.0 now.
Parent.transform.rotation = Quaternion.LookRotation(StartForward, StartUp); // i can rotate the at the direction I want it.
But after I unparent my Eye the position of the local(which is also global) is set to a different value. And after I parent it back, its set to the old value again.
Eye.parent = null; //unparent my eye to the world - Eye moves anyway because its movend by SteamVR
Parent.transform.position = Eye.position; //set my Parent to the same position as Eye (works)
Eye.parent = transform; //parent it back. Local Eye moves back where it was and there is a distance between parent and eye again.
Parent.transform.rotation = Quaternion.LookRotation(StartForward, StartUp); // the rotation changing my eyes position because its parented. Also the rotation is wrong.
And now i dont know anymore how to solve this problem.
so... i painted my problem in paint for better understanding: