- Home /
What is wrong with my RotateAround?
Hey all!
I wrote this script and i attached to my camera:
void Start()
{
if (rigidbody) rigidbody.freezeRotation = true;
cursorPosition = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
cursorDiff = new Vector2(0.0f, 0.0f);
}
void UpdateCursorDiff()
{
cursorDiff = cursorPosition - new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
cursorPosition = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
}
void UpdateLookDirection()
{
characterHead.transform.RotateAround(new Vector3(0.0f, 1.0f, 0.0f), -(cursorDiff.x * Time.smoothDeltaTime) * cursorSensitivity);
characterHead.transform.RotateAround(new Vector3(1.0f, 0.0f, 0.0f), (cursorDiff.y * Time.smoothDeltaTime) * cursorSensitivity);
characterHead.transform.eulerAngles = new Vector3(characterHead.transform.eulerAngles.x, characterHead.transform.eulerAngles.y, -90.0f);
}
void Update()
{
UpdateCursorDiff();
UpdateLookDirection();
}
But my character's head vibrates and when i move my mouse his head turns back to its original state... Can anyone help me?
(Sorry for my bad english! I am hungarian.)
FWIW there is a massive discussion of this sort of thing on unityGE$$anonymous$$S.com - quaternions etc.
Your English is incredibly better than my Hungarian :-)
Ohh o.O Thanx guys! I tought $$anonymous$$ouse X & Y returns the current mouse position not the difference :P
Answer by AeonIxion · Oct 31, 2012 at 08:19 AM
I'm not sure, but I'm guessing it's because you use Input.GetAxis("Mouse X"). Mouse X returns the movement of your mouse's x since the last frame. So if you don't move your mouse, it returns 0.
Unless you changed something in the Input inspector of course....
Your answer
![](https://koobas.hobune.stream/wayback/20220613083118im_/https://answers.unity.com/themes/thub/images/avi.jpg)