- Home /
Model Viewer Camera Rotation
I've been working in Unity for quite a while, and I hate asking simple questions like this, but quaternions still baffle me.
I need to make a CameraController with rotation functionality. The camera will have focus on different objects at various points, and I need the ability to rotate around the object (left, right, up and down).
Right now, this is what I have:
public void RotateRight() {
transform.RotateAround(focusObject.transform.position, Vector3.down, rotationSpeed * Time.deltaTime);
}
public void RotateLeft() {
transform.RotateAround(focusObject.transform.position, Vector3.up, rotationSpeed * Time.deltaTime);
}
public void RotateUp() {
transform.RotateAround(focusObject.transform.position, Vector3.right, rotationSpeed * Time.deltaTime);
}
public void RotateDown() {
transform.RotateAround(focusObject.transform.position, Vector3.left, rotationSpeed * Time.deltaTime);
}
Ultimately, these functions will be called by UI interactions (thus their segregation).
The Up/Down and Left/Right work just fine, so long as their not used together. As soon as I start combining rotations (or rotating Up/Down after Left/Right, etc), everything falls apart so to speak.
I'm not sure how to explain how I want this to function, so better to just show an example: https://sketchfab.com/models/08d80ef4bc2d4ab3a57b5b3ff227856d
This is easy to do if I rotate the OBJECT, and not the camera, but that is not an option for me.
In a nutshell, how would I go about duplicating the rotation functionality of the sketchfab viewer?
You're looking for an orbital camera: http://mentalogicus.blogspot.fr/2012/02/comment-faire-une-camera-orbitale-en.html
Looks promising, thanks! Hopefully Google's translate is good enough to maintain the technical accuracy of the article.
I'll have a deeper look at it tomorrow.
If you want to convert this to an answer, I'll gladly accept it. After some tweaking for my own scene, the provided tutorial was great! Thanks again
Your answer
Follow this Question
Related Questions
Rotation of player based on camera direction and joystick direction in 3D world 1 Answer
Rotate camera only in 2 directions based on player touch 1 Answer
Mouse axes based on position, not movement. 1 Answer
player rotate to camera direction but not moving in it's direction 0 Answers
How to set the player in front of the camera in any rotation 1 Answer