- Home /
Why is my Camera rotation tilted after parenting it to head?
When I parent my Camera to my player's head is rotated sideways 90 degrees and tilted 90 degrees. In my Start() I'm parenting it to the head then setting the position and rotation to that of the head. It might be gard to see on the photo but the camera is pointing sideways instead of straight ahead of her and it's rotate so instead of orbiting up and down it looks left and right but thet axes is set right and the camera pans fine when it's not parented.
void Start()
{
fpsCam = GameObject.Find("FPSCam").GetComponent<Camera>();
head = GameObject.Find("Head");
fpsCam.transform.parent = head.transform;
fpsCam.transform.localPosition = Vector3.zero;
fpsCam.transform.localRotation = head.transform.rotation;
}
You can set it in Inspector to the right position. No need the script I$$anonymous$$O.
Answer by Rhylvin2015 · Jul 28, 2015 at 01:36 AM
If you still wanna use the script I suggest not using
fpsCam.transform.localRotation = head.transform.rotation;
your head is probably rotated if its not i suggest using
fpsCam.transform.localRotation = head.Quaternion.identity;
head is a GameObject and GO's don't have a definition for Quaternion. I have to assign the Camera in code because I'm generating the character at runtime.