这个问题,摄像机拍摄主角,当主角被墙遮蔽了视野,那么就用正上方的点和当前相机所在位置的店为起始点和终点,从二者之间再找出三个关键点进行射线检测,能看到主角的店即可作为摄像机的transform.position Vector3[] posArray;
Vector3 beginPos = player.transform.position + offset;
Vector3 endPos = player.transform.position + offset.magnitude * Vector3.up;
for (int i=0; i<5; i++) {
Vector3 tmp = beginPos + (endPos - beginPos) / 4 * i;
RaycastHit hitInfo;
if (Physics.Raycast (tmp, player.transform.position - tmp, out hitInfo)) {
if (hitInfo.collider.tag != Tags.Player) {
continue;
} else {
transform.position = tmp;
break;
}
}
}
transform.LookAt (player.transform.position);