简体   繁体   English

如何防止相机绕Z轴局部旋转

[英]How to prevent camera local rotation around Z axis

I'm using the transform.LookAt method. 我正在使用transform.LookAt方法。 However, my camera is doing a rotation around its local Z axis. 但是,我的相机正在绕其本地Z轴旋转。 This is a two 90 degrees rotation that happens very fast. 这是两个90度的旋转,发生得非常快。 It completely annoys me. 这让我很烦。

There is some way to prevent it to do that? 有什么方法可以防止它吗? Maybe by locking the Z axis. 也许通过锁定Z轴。 Or by using some other method that can do the rotation smoother. 或者使用其他一些方法可以使旋转更平滑。

I've been trying every approach that had been posted at Unity Questions without success. 我一直在尝试在Unity Questions上发布的每一种方法都没有成功。

Thank you! 谢谢!

This is how I do it: 这是我的方法:

cam.transform.rotation = Quaternion.Euler(cam.transform.eulerAngles.x, cam.transform.eulerAngles.y, 0);

This fixes the rotation in the Z axis. 这样可以固定Z轴上的旋转。

It isn't what I was trying to do, but anyway, I found this script http://wiki.unity3d.com/index.php/SmoothLookAt_CS and it is very useful. 这不是我要尝试的操作,但是无论如何,我找到了该脚本http://wiki.unity3d.com/index.php/SmoothLookAt_CS ,它非常有用。 All the rotations of my camera happen very smoothly. 相机的所有旋转都非常顺利。

It doesn't prevent any axis to rotate however it compensates all the weird and clumsy moves of the original LookAt. 它不会阻止任何轴旋转,但是会补偿原始LookAt的所有怪异而笨拙的移动。 I'm very satisfied with the results by using it. 通过使用它,我对结果非常满意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM