unity3d - Unity3D:需要帮助旋转角色而不涉及位置
问题描述
使用 Unity3D 2018.2.8
我试图在不涉及/改变位置的情况下旋转我的角色(以第一人称)。
相机附在角色身上。因此,在移动角色时,摄像机也随之移动。我想做一个拖动类型的触摸来移动对象旋转 360 度。
不确定我是否使用此代码以正确的方式前进
另外,我应该Quaternion
用来控制旋转吗?
是相机targetToLookAt
所在物体的变换
public Camera cameraSelf;
private Transform cameraTransform;
private Vector2 cameraRotation;
void FixedUpdate() {
// Camera.transform to be the same as camera targets body
cameraSelf.transform.position = targetToLookAt.GetChild(0).GetChild(0).position;
cameraSelf.transform.rotation = targetToLookAt.GetChild(0).GetChild(0).rotation;
// Moving camera with Mouse
float pointer_x = Input.GetAxis("Mouse X");
float pointer_y = Input.GetAxis("Mouse Y");
// Using Touch
pointer_x = Input.touches[0].deltaPosition.x;
pointer_y = Input.touches[0].deltaPosition.y;
// Mouse Movement
cameraRotation.x += pointer_x * moveSensitivity * Time.deltaTime;
cameraRotation.y -= pointer_y * moveSensitivity * Time.deltaTime;
// Set Rotation of Object
targetToLookAt.position = cameraRotation;
}
解决方案
推荐阅读
- python - 将一个列表的每个索引与同一列表的每个其他索引进行比较的最佳方法
- android - 找不到符号 String token = task.getResult().getToken();
- python - 如何将字符串转换为输入函数中输入的整数?
- sql - 错误:类型间隔的无效输入语法
- html - 滑动不仅适用于移动 android chrome。(Vue)
- flutter - Flutter:如何使用动画移动到 ListView 中的最后一个位置
- java - 使用N个线程处理列表,如果服务时间大于T则超时
- cmd - cmd 在粘贴时将 em-dash 转换为连字符。任何解决方法?
- pandas - hy中pandas列设置的宏
- javascript - 动态插入新行后总数的增量和更新值