- Home /
Character Controller removes possibility of camera yaw?
This is probably a silly question, but I can't figure it out. I want my character controller camera to rotate around the Z axis, AKA I want it to "Yaw".
theCamera = GameObject.Find ("Main Camera");
theCamera.transform.localRotation = Quaternion.Euler(0f,0f,45f);
The rotation is applied, because this line tells me so:
print(theCamera.transform.rotation.eulerAngles);
Yet the camera physically does not respond to my code. It does not rotate. I know that it must be the Character controller which is stopping this. How can I get around this?
It is not the character controller. I just ran a quick test, and I had no problem. Note I used:
Camera.main.transform.localRotation = Quaternion.Euler(0f, 0f, 45f);
But since your code did not generate a null reference exception, I assume the GameObject.Find() is working.
Do you have any scripts on the camera? Smooth Follow, or $$anonymous$$ouse Orbit, or something else?
Thank you for replying. I must be missing something though.
I started up a new scene, added a default First Person Controller and added this script to it:
public class test : $$anonymous$$onoBehaviour {
void Update () {
Camera.main.transform.localRotation = Quaternion.Euler(0f, 0f, 45f);
}
}
The camera was still perfectly upright; the code did not work. It appears to be caused by the $$anonymous$$ouselook script attached to the camera. If I disable it, the code works.
So it's specifically that code which is doing it. I'll have a look inside to see if I can solve it. Could you (or someone) please help?
Ahha! It's the code on line 53 in the $$anonymous$$ouselook Script. It sets the Z rotation to 0 every frame.
Now I have a different problem. I need to take control of the rotation, but I'm using C# and $$anonymous$$ouselook is Java. I heard it's a nightmare to pass variables between these two. Is this true?
You have to get the compilation order right. For example if you drop your Javascript in StandardAssets, then you should not have trouble accessing the class from C#. $$anonymous$$ore information on compilation order can be found here:
http://docs.unity3d.com/Documentation/$$anonymous$$anual/ScriptCompileOrderFolders.html