작성
·
296
0
안녕하세요.
강의 코드를 진행하면서 유니티 실행 후 테스트 과정 시 대각선끼리의 방향 이동에 대해 이상이 있어 질문드립니다.
일반적인 이동은 무리가 없고 임의의 대각선 방향에서 바로 반대쪽 대각선 방향으로 움직일 때 Rotation을 하지 않고 움직이는 현상이 있습니다. Quaternion.Lerp의 3번째 인자 값인 Rotation하는 속도 문제인 것 같아서 0.5f로 하니 문제는 없는 것 같은데 해당 현상이 발생하는 정확한 이유를 모르겠습니다.
if (Input.GetKey(KeyCode.W))
{
transform.position += Vector3.forward * Time.deltaTime * _speed;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.forward), 0.2f);
}
if (Input.GetKey(KeyCode.A))
{
transform.position += Vector3.left * Time.deltaTime * _speed;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.left), 0.2f);
}
if (Input.GetKey(KeyCode.S))
{
transform.position += Vector3.back * Time.deltaTime * _speed;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.back), 0.2f);
}
if (Input.GetKey(KeyCode.D))
{
transform.position += Vector3.right * Time.deltaTime * _speed;
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.right), 0.2f);
}
답변 1
0
위 코드는 정말 간단히 테스트하기 위함이고,
대각선 이동을 고려한다면 이렇게 여러 번에 나누어서
transform.rotation =...
~을 하는게 아니라 대각선 방향에 맞춰서 한 번에 해줘야 합니다.
위 코드는 정말 간단한 실습용 코드라고 생각해주시면 되겠습니다.