unity 一个物体相对另一个物体坐标系的偏转角度计算
2016-06-17 15:43
459 查看
using UnityEngine; using System.Collections; public class UserAnimatorMove : MonoBehaviour { private Vector3 oldVector3; private Vector3 newVector3; private Quaternion oldQuaternion; private Vector3 newRotatinForward; void Start() { } void Update() { if (Input.GetKeyDown(KeyCode.F1)) { oldVector3 = this.transform.position; oldQuaternion = this.transform.rotation; } if (Input.GetKeyDown(KeyCode.F2)) { StartCoroutine(MovePoint()); } } private IEnumerator MovePoint() { // oldVector3 = this.transform.position; // oldQuaternion = this.transform.rotation; yield return new WaitForSeconds(0.2f); newVector3 = this.transform.position; newRotatinForward = this.transform.forward; float lenth = Vector3.Distance(oldVector3, newVector3); Vector3 velocity = Quaternion.Inverse(oldQuaternion) * newRotatinForward; float angle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f; Debug.Log(angle);//新的方向相对旧的方向的偏转角度 } }
相关文章推荐
- 重新启航,拥抱u3d
- Unity3d--判断鼠标是否触发UGUI控件
- Unity3D游戏开发之史上最简单的鼠标点击控制人物走动实现
- 将 Ubuntu 16.04 LTS 的 Unity 启动器移动到桌面底部
- 360全景漫游(unity3d + 暴风魔镜)
- 详细的介绍Unity5的AssetBundle
- Unity3d开发(十三)导出NavMesh可行走区域信息
- U3D前后端开发知识体系
- 第一人称视角漫游(unity + 暴风魔镜)
- Unity 获取所有子物体,不包括孙物体
- Unity 实用小技巧合集
- 【shadertoy】海洋球 -- unity中的水面特效shader
- unity 加载
- 【unity shader】高级光照 --- 薄膜干涉
- 最适合开发VR游戏大作的游戏引擎——Unity
- Unity录屏实现(一)
- Unity NetworkManager整理160616
- ScriptableWizard
- OpenGL shader 内置函数 和 unity3d shaderlib 内置函数对照表
- Unity脚本生命周期