- Home /
Question by
sagicoh · Dec 24, 2021 at 04:31 PM ·
rotationquaternionrotation axisrotatearound
Locking rotation makes object spin
Hey,
I'm trying to use the keybaord to rotate the camera around an object, And I dont want to rotate the camera around the z axis
here is my code:
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 rotationAxis = new Vector3(v, h, 0);
_cam.transform.RotateAround(_rotationOrigin, rotationAxis, _baseMoveSensitivity * Time.deltaTime);
_cam.transform.rotation = Quaternion.Euler(_cam.transform.rotation.eulerAngles.x, _cam.transform.rotation.eulerAngles.y, 0);
My problem is that although I dont rotate around the z axis, the camera spins when I move over the object. Is there a way to fix it?
Or do it in another way that will not cause that spin to occur?
Thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613050916im_/https://answers.unity.com/themes/thub/images/avi.jpg)