❗ 캐릭터가 벽에 가려지는 경우 캐릭터가 보이도록 카메라를 이동시키기 ❗
RayCast를 이용하여 벽을 탐지한다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
[SerializeField]
Define.CameraMode _mode = Define.CameraMode.QuarterView;
[SerializeField]
Vector3 _delta = new Vector3(0.0f, 6.0f, -5.0f);
[SerializeField]
GameObject _player = null;
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
if (_mode == Define.CameraMode.QuarterView)
{
RaycastHit hit;
if (Physics.Raycast(_player.transform.position, _delta, out hit, _delta.magnitude, LayerMask.GetMask("Wall")))
{
float dist = (hit.point - _player.transform.position).magnitude * 0.8f;
transform.position = _player.transform.position + _delta.normalized * dist;
}
else
{
transform.position = _player.transform.position + _delta;
transform.LookAt(_player.transform);
}
}
}
public void SetQuaterView(Vector3 delta)
{
_mode = Define.CameraMode.QuarterView;
_delta = delta;
}
}