Unity--旋转方法

来源:互联网 发布:个人理财软件 编辑:程序博客网 时间:2024/06/08 11:03
************************************************************************************
旋转自身坐标系--实现待旋转的物体的Z轴始终指向目标位置,这个可以用于追踪目标位置,

当目标在移动时,待旋转的物体,会始终保持Z轴指向该目标位置

1、public void LookAt(Transform target, Vector3 worldUp = Vector3.up);

Transform target;

transform.LookAt(target);

2、public void LookAt(Vector3 worldPosition, Vector3 worldUp = Vector3.up);

transform.LookAt(Vector3.zero);

************************************************************************************

在世界坐标系或者本地坐标系下 绕某个轴旋转---实现按照固定的顺序 绕各个轴旋转一定的角度

多用于自身要旋转的角度

3、public void Rotate(Vector3 eulerAngles, Space relativeTo = Space.Self);

// Rotate the object around its local X axis at 1 degree per second
        transform.Rotate(Vector3.right * Time.deltaTime);

        // ...also rotate around the World's Y axis
        transform.Rotate(Vector3.up * Time.deltaTime, Space.World);

4、public void Rotate(float xAngle, float yAngle, float zAngle, Space relativeTo = Space.Self);

// Rotate the object around its local X axis at 1 degree per second
        transform.Rotate(Time.deltaTime, 0, 0);

        // ...also rotate around the World's Y axis
        transform.Rotate(0, Time.deltaTime, 0, Space.World);

5、public void Rotate(Vector3 axis, float angle, Space relativeTo = Space.Self);

// Rotate the object around its local X axis at 1 degree per second
        transform.Rotate(Vector3.right, Time.deltaTime);

        // ...also rotate around the World's Y axis
        transform.Rotate(Vector3.up, Time.deltaTime, Space.World);

************************************************************************************
在世界坐标系下 绕固定点、固定方向旋转,

用于绕固定点旋转中,例如 地球绕太阳旋转等实例中,实现始终保持一定的半径旋转

6、public void RotateAround(Vector3 point, Vector3 axis, float angle);

transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
0 0
原创粉丝点击