我是靠谱客的博主 幸福鞋垫,这篇文章主要介绍Unity球面星球行走 向量投影 物体在面内按轴锁定LookAt旋转,现在分享给大家,希望可以做个参考。


复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//球体 GameObject ball; //用到的投影方法 public static Vector3 cast(Vector3 vector, Vector3 PlaneNorm)// vector要投影的向量,投影到以PlaneNorm为法线的面 { return vector + PlaneNorm * (Vector3.Dot(vector, PlaneNorm) * -1); } void LookAt(GameObject target) { transform.rotation = Quaternion.LookRotation(cast((target.transform.position - transform.position).normalized, -Physics.gravity), -Physics.gravity); } public void Rotate(float x) { transform.rotation.SetLookRotation(Quaternion.AngleAxis(x, -Physics.gravity) * transform.forward, -Physics.gravity); } void Rotate() { Physics.gravity = (ball.transform.position - transform.position).normalized; transform.rotation = Quaternion.FromToRotation(transform.up, -Physics.gravity) * transform.rotation; }

最后

以上就是幸福鞋垫最近收集整理的关于Unity球面星球行走 向量投影 物体在面内按轴锁定LookAt旋转的全部内容,更多相关Unity球面星球行走内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部