简体   繁体   English

无法在统一C#中按顺时针方向旋转图像

[英]Unable to rotate an image in clockwise direction in unity c#

I have an image to be rotated in a pivot point(top) through animation. 我有一个要通过动画在枢轴点(顶部)旋转的图像。 I am able to rotate it in anti-clockwise direction by simply changing the z-rotation value. 只需更改z旋转值 ,就可以沿逆时针方向旋转它 But I want to rotate an image in clockwise direction. 但是我想按顺时针方向旋转图像。

If I put a z-rotation value -45 degree, unity converts it to 315 degree and rotates an image in anti-clockwise direction. 如果我将z旋转值设为-45度,则将其单位转换为315度并沿逆时针方向旋转图像。

The image to be rotated has pivot point at top as shown in the figure below. 旋转的图像的枢轴点在顶部,如下图所示。

在此处输入图片说明

You could lerp the angle (single float) instaed of the entire rotation. 您可以控制整个旋转的角度(单个浮动)。 Lerp from your min angle to max angle and just directly set ,rotation = Quaternion.Euler(0,angle,0). 从您的最小角度到最大角度线性调整,只需直接设置,rotation = Quaternion.Euler(0,angle,0)。

There shouldn't be any issue with wrapping from 0 to 360; 从0到360换行应该没有任何问题; those are the same rotation (and so are 720 and -360, etc). 旋转相同(720和-360等)。

(you can't force slerp to go a different direction; it's wired to take the shortest route, just like lerp is (though, understandably, it's harder to tell with lerp)) (您不能强迫slerp朝不同的方向前进;它就像lerp一样,走了最短的路线(尽管可以理解的是,使用lerp很难说清楚))

maybe this code help : 也许这段代码有帮助:

 needleHub.transform.localRotation = Quaternion.Euler(0, 0, Mathf.LerpAngle(90f, -90f, lerpFactor));

Try changing the interpolation type. 尝试更改插值类型。 I remember having almost the exact same problem and fixing it by changing the interpolation to something other than Eulers Angles. 我记得遇到了几乎完全相同的问题,并通过将插值更改为Eulers Angles以外的内容来解决。

在此处输入图片说明

Thanks @UriPopov for your reference . 感谢@UriPopov供您参考 Finally I am able to rotate an image in clockwise direction through animation. 最后,我可以通过动画按顺时针方向旋转图像。 I change the rotation to EulerAngles(Quaternion) as said by UriPopov. 如UriPopov所述, 我将旋转更改为EulerAngles(Quaternion) But main point to be remember during this animation is that each animation frame should be considered. 但是在此动画过程中要记住的主要一点是,应该考虑每个动画帧。 If one frame is placed empty, then the animation will be in anti-clockwise direction. 如果将一帧放置为空,则动画将为逆时针方向。

在此处输入图片说明

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

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