- Home /
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
Does the code sample you posted include the code that's actually causing the problem?
No, the code that causes the problem is this: transform.rotation.y = cameraTransform.rotation.y;
Answer by billymcguffin · Apr 19, 2011 at 01:03 AM
Ah, ok. I found the answer. I had to use rotation.eulerAngles.y, not rotation.y.
Solved.
Your answer
Follow this Question
Related Questions
Mouselook snapping. 0 Answers
Realtime Object Rotation on iPad 0 Answers
Smooth rotation in 90° increments 0 Answers
How To Check If X Rotation Is Between Two Numbers?? 1 Answer
space flying system 3 Answers