- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
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;
}
}
}
}
|
|