Unity3D-Transform.TransformDirection

Transform.TransformDirection 变换方向
function TransformDirection (direction : Vector3) : Vector3
Description描述
Transforms direction from local space to world space.

This operation is not affected by scale or position of the transform. The returned vector has the same length as direction.

上面的取自Unity3d圣典

注意下面两个例子中的相机(相机需要加rigidbody去掉重力)移动的区别:

例1:

public Transform cam; 
    public Vector3 cameraRelativeRight;
    void Start () {
        cam = Camera.main.transform;
rigidbody.AddForce (Vector3.right*1000);}

相机参数变化情况:

Unity3D-Transform.TransformDirection_第1张图片

例2:

public Transform cam; 
   public Vector3 cameraRelativeRight;
    void Start () {
        cam = Camera.main.transform;
        cameraRelativeRight = cam.TransformDirection(Vector3.right);//转变变换
        rigidbody.AddForce (cameraRelativeRight*1000);}
Unity3D-Transform.TransformDirection_第2张图片

完毕。

欢迎各位不吝赐教!



你可能感兴趣的:(Unity3D)