- Home /
Getting the camera to rotate around player but not damp around them?
hey guys I have another question. I have been trying to get the camera to rotate around my player when the user holds down keys.
so for example if the user holds down the Z key, then the camera should rotate left and keep rotating until they release the key, if the user holds down X key the camera should rotate right and keep rotating around the player until they release it.
I want to do this without damping, In my camera script I disabled rotation damping, so now it only follows the player but doesnt follow their rotation and thats what I wanted. I want the user to be able to rotate the camera around the player left and right on key press.
you know very similar to most games that have this kind of camera control, for example in Zelda Wind Waker you can use the C stick to rotate the camera around link or in Monster Hunter, you can use the D-pad to rotate the camera left and right.
Iv looked all over unity, the website, answers, and the wiki (I found some mouse orbits in the wiki, but not exactly what im going for)
so far I have this code
var target :Transform ;
function Update ()
{
if(Input.GetKeyDown(KeyCode.Z))
{
transform.LookAt(target);
}
transform.Translate(Vector3.right * Time.deltaTime);
}
of course this code doesnt work, im trying to getting it going, no luck though.
thanks for any help in advance! :)
Answer by Winterblood · Jan 03, 2012 at 11:03 PM
Here's how I'd do it - create a dummy gameobject at the target position and parent the camera to it. Then add this to the dummy object (not the camera). The camera should then follow the player without rotating, and rotating the dummy will orbit the camera around the player.
var target :Transform ;
function Update ()
{
var rot : Vector3 = transform.rotation.eulerAngles;
if(Input.GetKeyDown(KeyCode.Z))
{
rot.y += 45 * Time.deltaTime;
}
transform.position = target.position;
transform.rotation.eulerAngles = rot;
}
Thanks works great, It doesnt keep rotating while holding down a key, you have to keep pressing the key to rotate however much you want, but still it works great and is how I imagined it to work. Besides I can make a couple of modifications to it.
Thanks a lot :)
Sorry, my bad - if you use Input.Get$$anonymous$$ey ins$$anonymous$$d of Get$$anonymous$$eyDown, it'll continue rotating while you hold the key pressed.
Your answer

Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Unity3d or Maya-style Camera navigation 5 Answers
Changing the Camera Control 2 Answers
Third Person Camera Control 2 Answers