# Rotation Jerks when Copying From Different Object

Hi all.

I have a character and a cameraPivot object. The camera pivot uses this modification of the 3rd person camera script:

``````function Update() {
if(Input.GetKeyDown(KeyCode.LeftBracket)){
sensitivity --;
} else if (Input.GetKeyDown(KeyCode.RightBracket)){
sensitivity ++;
}

if(sensitivity < 1){
sensitivity = 1;
}

x += Input.GetAxis("MouseX") * sensitivity * 0.02;
y -= Input.GetAxis("MouseY") * sensitivity * 0.02;

if(y > capAmount){
y = capAmount;
} else if(-y > capAmount){
y = -capAmount;
}

if(x >= 180){
x -= 360;
} else if(x <= -180){
x += 360;
}

myTransform.rotation = Quaternion.Euler(y, x, 0);
}

``````

As you can see, if the vertical rotation gets to 180 or -180 (turned completely around from the original rotation), it will change the rotation to be the same rotation but represented by a number in between 180 and -180.

The problem arises, however, when I try to make the character copy this rotation. When I press the W key, the character should rotate to face away from the camera (copies the y component of the camera pivot's rotation to the y component of the character's rotation). When the rotation gets to within about 10 degrees of 180 or -180, the character refuses to rotate until the rotation is outside of this 10 degree 'limit'. This causes the character to snap to the correct rotation after leaving the 'limit', which is quite undesirable.

I've tried using Lerp and Slerp to change the rotation, but that makes it worse.

Here's a video of my problem because my explanation sucked: http://www.youtube.com/watch?v=CbQx_Snzdek

Thanks to anyone who can help! :D

Ah, ok. I found the answer. I had to use rotation.eulerAngles.y, not rotation.y.

Solved.