unity3d - Unity - 围绕 2D 中的点旋转对象
问题描述
我一直在 Unity 中开发 2D 游戏,我需要找到一种方法来围绕某个点旋转精灵。我知道对于 3D 游戏,Unity 有一个内置transform.RotateAround()
功能,但我不确定如何实现 2D 等效。如果有人可以提供帮助,将不胜感激。
解决方案
您可以使用相同的功能。transform.RotateAround()
需要 a Vector3 point
、 aVector3 axis
和 afloat angle
度数。
点和角度很容易解释,但轴有点不那么清楚。这本质上是旋转方向。在默认的 Unity2D 游戏中,z 是您的深度(进入屏幕),您需要绕 Z 轴旋转:new Vector3(0,0,1)
或Vector3.forward
.
尝试类似:
Vector3 point = new Vector3(5,0,0);
Vector3 axis = new Vector3(0,0,1);
transform.RotateAround(point, axis, Time.deltaTime * 10);
推荐阅读
- python-pptx - python-pptx:如何在新插入的幻灯片中查询文本占位符的“默认”值
- java - Java中带有一些特殊字符的String到Map的转换
- jquery - 在 Polymer 中动态创建的行中调用函数
- node.js - 避免缩小流星中的某些包
- android - 创建了一个自定义布局对话框,但在对话框窗口外单击时无法关闭对话框
- r - 管道列名到断言
- r - MCAR 测试错误(来自 naniar 包):变异和“条件数”的问题
- python - 如何使用 python 在文件资源管理器中打开文件夹?
- javascript - 在 Node.js Express 上托管 Vue.js 应用程序 - 在 cPanel 上 - 仅加载 index.html
- javascript - 在 Java 中使用 JavaScript 函数:异常