c# - 沿 Vector3 轴设置旋转?
问题描述
我正在构建一个具有任意“向下”感的控制器,因此我无法使用正常的相机移动方法。
我可以很好地在上/右轴上移动相机,但这会产生不需要的“滚动”。我环顾四周/尝试了很多,但找不到一种在任意“前向”轴上设置此相机旋转而不搞砸其他运动的好方法。
有任何想法吗?
解决方案
使用四元数乘法根据相关输入(此处使用鼠标作为示例)围绕任意向上轴(您可以使用Quaternion.AngleAxis找到它)及其局部 x 轴旋转相机:
Vector3 myUp = Vector3.up; // set with arbitrary up
float rotationSpeed = 1f;
// ...
float horizMouseMove = Input.GetAxis("Mouse X") * rotationSpeed;
float vertMouseMove = Input.GetAxis("Mouse Y") * rotationSpeed
transform.rotation = Quaternion.AngleAxis(horizMouseMove, myUp)
* transform.rotation
* Quaternion.EulerAngles(-vertMouseMove, 0f, 0f);
推荐阅读
- javascript - Node.js 返回空数组
- gatsby - 如何使用迁移的 HTML 内容为 Gatsby 创建博客条目
- dialogflow-es - 谷歌助手拒绝登录时多次给出相同的响应
- c# - 使用 C# 检索 MongoDB 文档并选择一个字段
- python - 字符串中隐藏的 unicode 字符集
- angular - 如何使用 Angular 2 Alert(Toaster) 设置超时警报消息
- c# - 如何在页脚中显示 SharedAssemblyInfo.cs 详细信息
- javascript - Angular map http response value with another http call
- javascript - 使用 jQuery 在滚动功能上检测 translate3d 的变化
- python - 尝试加载我的 json 文件时遇到此错误:json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)