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.)