강의

멘토링

로드맵

Inflearn Community Q&A

barricade300268's profile image
barricade300268

asked

[MMORPG Game Development Series with C# and Unity] Part3: Unity Engine

Rotation

로테이션 동시에 2개의 키를 눌렀을때에 대하여

Resolved

Written on

·

204

0

안녕하세요

로테이션 부분중  동시에 키를 입력했을 때에 대해서 궁금한 점이 생겨 질문드리게 되었습니다

if (Input.GetKey(KeyCode.W))

        {

            transform.rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));

  }

        

        

        if (Input.GetKey(KeyCode.S))

        {

            transform.rotation = Quaternion.Euler(new Vector3(0.0f,180.0f,0.0f));

        }

            

        if (Input.GetKey(KeyCode.A))

        {

            transform.rotation = Quaternion.Euler(new Vector3(0.0f, 270.0f, 0.0f));

        }

            

        if (Input.GetKey(KeyCode.D))

        {

            transform.rotation = Quaternion.Euler(new Vector3(0.0f, 90.0f, 0.0f));

        }

위와 같이 코딩되어 있을 때  W 와 D를 같이 누르면 앞을 한번 봤다가 오른쪽을 한번 보는 하는 행동을 반복해야하는 것 아닌가요? 

테스트를 해보니 오른쪽만을 바라보네요

왜 그런 것인가요?

C#unity

Answer 1

1

Rookiss님의 프로필 이미지
Rookiss
Instructor

transform.rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));
을 넣어주는 그 순간 뭔가가 일어나는게 아닙니다.

우리가 넣어주는 좌표/회전이 다음 프레임에
gpu에 의해 계산되고 화면에 렌더링 되어야 우리가 볼 수 있는건데
위 코드에서
transform.rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));
로 최종값을 덮었으니 오른쪽으로만 바라보게 되는겁니다.

barricade300268's profile image
barricade300268

asked

Ask a question