有个项目,需要运行的时候先转到某个任意的角度,再转回来
我开始的思路是先获取对象的角度,然后再随机转到某个角度,最后再转到开始获取的角度
![](https://img.haomeiwen.com/i2900438/e612f0d96e34a3ae.png)
问题是,单个轴向的转动转回来没问题,两个以上的轴向转动就转不回原来的角度了,而且我把角度打印出来也是正确的
比如上面的例子中,我转了x=30,y=70,z=0,按理来说要转回来就是x=-30,y=-70,z=0
结果最后转到的位置和开始的位置差远了...................
![](https://img.haomeiwen.com/i2900438/b9c45df9dd3ad813.png)
![](https://img.haomeiwen.com/i2900438/17aac93afc6f3119.png)
![](https://img.haomeiwen.com/i2900438/791f2a6f521f2970.png)
造成这个的原因其实很简单,原来的旋转XYZ的角度表示的内容不全,导致了旋转过程中有坐标系的变化从而导致了最后结果的错误,详情参考
所以unity给了我们另外的一个东西来描述角度
这个理解起来非常抽象,但是计算机很清楚是什么而且内容全面
They are based on complex numbers and are not easy to understand intuitively. You almost never access or modify individual Quaternion components (x,y,z,w); most often you would just take existing rotations (e.g. from the Transform) and use them to construct new rotations (e.g. to smoothly interpolate between two rotations). The Quaternion functions that you use 99% of the time are: Quaternion.LookRotation, Quaternion.Angle, Quaternion.Euler, Quaternion.Slerp, Quaternion.FromToRotation, and Quaternion.identity. (The other functions are only for exotic uses.)
官方的意思就是,大家不用管里面什么什么的意思,直接用就是啦
![](https://img.haomeiwen.com/i2900438/6c3af09ee3a026e7.png)
问题解决,遗憾的是DoTween里面的这个函数的参数太少
![](https://img.haomeiwen.com/i2900438/f6741d7f4cad72c8.png)
官方也说了,这个是旋转首选的方式
不过最大的问题解决了,其他就自己写吧
网友评论