用手指拖动使精灵围绕枢轴旋转 [英] Rotate sprite around pivot with finger drag

查看:101
本文介绍了用手指拖动使精灵围绕枢轴旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绕时钟中心旋转时针,并且正在使用:

I am rotating a clock hand around clock center, and I am using:

Vector3 dir = mouseClickPos - transform.position;
float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

它的工作就像一种魅力.但是我需要它不要走得很平稳,而要跳过15度左右.我该怎么办?

And it is working like a charm. But I need it not to go smooth but to skip around 15 degrees. How can I do that?

推荐答案

尝试

angle=Mathf.Round(angle/15f)*15f

(对不起,一开始数学错误,需要喝咖啡)

(sorry for the wrong math at first, need coffee)

这篇关于用手指拖动使精灵围绕枢轴旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆