目录
1.位移计算公式
一维坐标系:路程=速度*时间;
多维坐标系:路程=速度*方向*时间;
2.直接计算的方法
position=当前位置+移动距离
this.transform.position=this.transform.position+this.transform.up*1*Time.deltaTime;
它会始终朝向自己面向的位置移动。
方向非常重要,因为它决定了前进方向
this.transform.position+=Vector3.forward*1*Time.deltaTime;
3.API计算方法
参数一:位移的多少。
参数二:相对的是什么坐标系
//1相对世界坐标系Z轴动
this.transform.Translate(Vector3.forward*1*Time.deltaTime,Space.World);
//2相对世界坐标的,自己的面朝向去动,始终朝自己的面朝向移动
this.transform.Translate(this.transform.forward*1*Time.deltaTime,Space.World);
//3相对于自己的坐标系下,自己面朝向量移动(一定不会让物体这样移动)
this.transform.Translate(this.transform.forward*1*Time.deltaTime,Space.Self);
//4相对于自己的坐标系下Z轴正方向移动,始终朝自己的面朝向移动
this.transform.Translate(Vector3.forward*1*Time.deltaTime,Space.Self);
一般使用API来进行位移。