본문 바로가기
개발 공식/Unity

unity transform rotation Rotate RotateAround

by JinCoding 2022. 11. 22.
반응형

유니티 회전

잊을만하면 각도변경을 해야하는 경우가 있다.

매번 구글링 해서 찾게 되는대..

 

transform rotation

 private void Start()
        {
            GameObject test = new GameObject();
            test.transform.rotation = Quaternion.Euler(new Vector3(x, y, z));
        }

rotation은 오브젝트 절대적인 각도를 지정하는 것이다.

test의 각도를 new Vector3(x, y, z)로 고정시킬 때 사용한다.

 

transform Rotate

        private void Update()
        {
            GameObject test = new GameObject();
            test.transform.Rotate(new Vector3(x, y, z) * Time.deltaTime);
        }

Rotate는 오브젝트 각도의 변경을 지속적으로 실행할 때 사용한다.

즉, 회전시킬 때 사용하는 것으로

test의 각도를 new Vector3(x,y,z) 방향으로 매 프레임마다 이동시킨다.

 

transform RotateAround

        private void Update()
        {
            GameObject test = new GameObject();
            GameObject target = new GameObject();
            test.transform.RotateAround(target.transform.position, Vector3.up, 10 * Time.deltaTime);
        }

RotateAround는 target 포지션을 기준으로 회전한다.

target의 위치, 회전방향, 회전속도를 지정한다.

Rotate와 RotateAround는 기준이 target인지 오브젝트 자신인지의 차이점을 가진다.

반응형

댓글