纳金网
标题:
摄像机穿墙时自动缩小距离
[打印本页]
作者:
ku
时间:
2013-2-19 21:45
标题:
摄像机穿墙时自动缩小距离
Unity3D脚本:摄像机穿墙时自动缩小距离
class SoldierCamera : MonoBehaviour { private Transform target; private Transform camTransform; public LayerMask hitLayer; private Vector3 cPos; public float normalDistance; private float targetDistance; private Vector3 camDir;
void Start () { }
void LateUpdate () { CameraMovement(); }
void CameraMovement() { camDir = (camTransform.position - target.position).normalized; cPos = target.position; targetDistance = Vector3.Distance(camTransform.position,target.position);
RaycastHit hit; if (Physics.Raycast(cPos, camDir, out hit, targetDistance + 0.2f, hitLayer)) { float t = hit.distance - 0.1f; camTransform.position = t * camDir + cPos; } else { if (targetDistance != normalDistance) { float t = Mathf.Lerp(targetDistance,normalDistance,Time.deltaTime * 15); camTransform.position = t * camDir + cPos; } } }
}
作者:
王者再临
时间:
2013-2-21 03:55
这个不错,先收藏下了。谢谢!!
作者:
jjiezheng
时间:
2013-8-23 09:07
不错,有点价值
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5