简体   繁体   中英

How to prevent camera local rotation around Z axis

I'm using the transform.LookAt method. However, my camera is doing a rotation around its local Z axis. This is a two 90 degrees rotation that happens very fast. It completely annoys me.

There is some way to prevent it to do that? Maybe by locking the Z axis. 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.

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.

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. 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. I'm very satisfied with the results by using it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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