您的位置:首页 > 移动开发 > Unity3D

Unity摄像机跟随Target快速位移和旋转

2015-10-28 10:42 489 查看
[html] view
plaincopyprint?

public Transform target;

public float distance ;

public float targetHeight;

public float PitchAngle;

private float x = 0.0f;

private float y = 0.0f;

void Start () {

var angles = transform.eulerAngles;

x = angles.x;

y = angles.y;

}

void LateUpdate ()

{

if(!target)

return;

y = target.eulerAngles.y;

// ROTATE CAMERA:

Quaternion rotation = Quaternion.Euler(x-PitchAngle, y, 0);

transform.rotation = rotation;

// POSITION CAMERA:

Vector3 position = target.position - (rotation * Vector3.forward * distance + new Vector3(0,-targetHeight,0));

transform.position = position;

}

/article/7791761.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: