- Home /
Setting Main Camera Rotation
I can't figure out how to set the rotation of the camera to an exact set of x,y,z values using C#. Once I realized that transform.position could set the position in a similar way to using the inspector, I figured it would be just as easy for the rotation. I need to set the camera for multiple positions for an rpg (map, third person, first person etc). I figured I save a flowing move of the camera for later. Any help would be greatly appreciated.
Answer by whydoidoit · May 28, 2012 at 07:32 PM
Don't worry, it's very simple:
Camera.main.transform.rotation = Quaternion.Euler(x,y,z);
There's some smooth move stuff on my blog - http://www.whydoidoit.com - smoothed quaternions, moving on a path - but that ain't rocket science either :)
Thanks, that worked, I can zap the view point around in the unity asset dungeon (the coolest thing I've done in unity). I checked out your blog and found the "Path $$anonymous$$ove and Character Speed" section. This looks like what I might need to move the character forward to the door. So, I'll look into what a Spline, a path and the currently targeted path point is and see if I can figure out how to impliment it.
Well that move on path will move between a number of locations in a smooth manner, kind of controlled - I use it to move cameras on switchable tracks.
The smooth stuff is just a wrapper around a bunch of functions that you can call directly like Lerp and smoothdamp which make normal movements less jerky.
Answer by hockey77 · Apr 11, 2020 at 09:06 PM
currentRotation.x += Input.GetAxis("Mouse X") sensitivity; currentRotation.y -= Input.GetAxis("Mouse Y") sensitivity; currentRotation.x = Mathf.Repeat(currentRotation.x, 360); currentRotation.y = Mathf.Clamp(currentRotation.y, -maxYAngle, maxYAngle); Camera.main.transform.rotation = Quaternion.Euler(currentRotation.y,currentRotation.x,0); if (Input.GetMouseButtonDown(0)) Cursor.lockState = CursorLockMode.Locked;
That could be the answer:D
Answer by joedt100 · Sep 11, 2017 at 05:46 PM
@whydoidoit This doesn't work for me as when I try to set exact rotations for the camera it doesn't do anything at all.
Your answer
Follow this Question
Related Questions
Quaternion Slerp Sanity Check 1 Answer
How to freeze the rotation or the position on the camera transform? 1 Answer
how do i make first person character rotate left and right along with camera? 0 Answers
Override Oculus Orientation 5.3 1 Answer
How to make the camera rotate only when right click is held down on the mouse? 1 Answer