Unity/참고자료

월드 좌표계와 로컬 좌표계

치명적흑형 2021. 10. 5. 17:54

월드 좌표계 transform.position

월드 좌표계란 오브젝트가 게임판 어디에 있는지를 나타낸다.

Inspector 창에서 설정한 좌표는 월드 좌표계이다.

 

로컬 좌표계 transform.localPosition

로컬 좌표계는 게임 오브젝트가 개별적으로 갖는 좌표계이다.

 

Transform 메서드를 사용하면 이동 방향은 월드 좌표계가 아닌 로컬 좌표계로 계산.

따라서 오브젝트가 회전하면 방향이 회전한 좌표계로 계산된다.

회전하면서 동시에 이동할 때는 조심해야된다.


Veter.up (0,1,0)

월드좌표

 

Transform.up (0,1,0)

로컬좌표


게임 오브젝트의 기본 좌표 : 로컬 좌표

툴바의 로컬 확인

 

 

월드좌표로 변경시

툴바의 글로벌 확인

 


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //this.transform.Translate(0, 0, 0.1f, Space.Self);
        this.transform.Translate(0, 0, 0.1f, Space.World);
    }
}

셀프와 월드의 이동 방향이 다르다.