- Home /
how to change orbit camera rotation when player runs into trigger box
I have recently created an object teleporter script that that teleports the player to specific location and it changes the player's rotation if specified. Also, I want the script to tell the main camera to change it's rotation when the player touches the trigger box. I have tried using:
Camera.main.transform.rotation = Quaternion.Euler(newRotation)
but nothing happens. (newRotation is a vector3 var)
Another thing is that earlier in this project, I accidently deleted the pre made Main Camera that comes with the start of the project. So I tried remaking the main camera by spawning one, naming it "Main Camera" and tagging it respectively like the original. I was wondering if this would be part of the problem whether Camera.main is not responding to this.
You could test that theory by declaring the camera with public Camera theCamera and then drag your Camera in the hierarchy into that public reference point, then change Camera.main to theCamera. I doubt that's the problem if you recreated/retagged though. Do you have any code on your player's movement control scripts that might be clamping or locking the camera?
Not in the player movement script but in my orbit camera control script(attached to main cam). All horizontal movement is free from clamping, and vertical movement is clamped to +-60 degs(adjustable). The camera is not locked and it can be freely controlled by the player. The teleporter script is suppose to tell the main camera what angle to rotate to when the player runs into the trigger. That is why I'm using Camera.main which is suppose to be assigned to the first camera automatically. I believe dragging the camera to the public variable is too many steps.
I suggested the public Camera reference part just to test your suggestion of a possible corrupt Camera.main (the drag/drop would bypass that shortcut) but I doubt that's the issue. When I can't find my logic error, I usually fallback to
Debug.Log("Rotating Camera.main to " + newRotation);
just to ensure I'm getting to the suspect bit of code and that my variable contains the value I'm expecting.
Answer by Kalbytron · Sep 10, 2013 at 07:39 AM
Thanks for the feedback guys, but I have already figured it out on my own. All I had to do was write:
Camera.main.SendMessage(function name, rotation values, don't required feedback)
This worked out for rotating the camera to a new angle after teleporting.
Your answer
Follow this Question
Related Questions
move camera when it collides with a trigger 1 Answer
Move JoyStick Together With Camera 1 Answer
enter a trigger to access other camera? 1 Answer
Active camera on Start 1 Answer
Camera distance from mesh not center 1 Answer