- Home /
How to ensure that an object always rotates toward the camera?
I'm trying to make a program that lets its user rotate a model horizontally and vertically to look at different parts of it. I have horizontal rotation all set up, but vertical rotation is proving difficult. I want the user to, no matter how they've rotated the model horizontally, be able to tilt the model toward and away from them, with a 20 degree limit so they cant flip it all the way upside down.
Simple rotation on either the X or Z axis makes it so that when you rotate horizontally another 90 degrees, youll be seeing a sideways version of the model.
How do I set the object up to rotate in relation to the main camera while the user holds down the up and down arrow keys?
This is my current script:
public float horizSpeed;
public float vertiSpeed;
public CharacterController cc;
public GameObject artiSphere;
void Start()
{
cc = GetComponent<CharacterController>();
}
void Update()
{
//horizontal rotation
cc.transform.Rotate (new Vector3(0.0f, Input.GetAxis ("Horizontal")*horizSpeed*Time.deltaTime,0.0f));
}
do I understand correctly that you'd like it to rotate a local y axis, and a fixed x or z axis, so that it rotates around its own y axis for horizontal rotation, and around a fixed axis limiting -20 to +20 degrees of rotation? So one control allows the camera to look on 'top' or 'bottom' of the object and it will still rotate along its local axis, where the other control rotates the local axis?
Or is it specifically camera-relative at all times (projected axis)
I don't want to rotate the camera if thats what you're asking, as I've tried that and it looked awkward and was hard to control. Projected axis sounds about right for what I'm trying to accomplish i think
Your answer
![](https://koobas.hobune.stream/wayback/20220611231258im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
How to detect if player had switched direction of movement? 0 Answers
Will someone please help me??? 2 Answers
Need help rotating child of player based off of player movement. 1 Answer
How to make the player rotate to where an object is being thrown? 1 Answer