본문 바로가기

Unity/ARCore

ARFoundation으로 ARCore 사용하기 - 객체를 중심으로 세상을 이동

ARFoundation으로 ARCore 사용하기 - 객체를 중심으로 세상을 이동

 

arSessionOrigin.MakeContentAppearAt에 대해 알아 보겠습니다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

public class MoveARWorldPivot : MonoBehaviour
{
    public Transform target;
    public ARRaycastManager arRaycastManager;
    public ARSessionOrigin arSessionOrigin;

    private List<ARRaycastHit> hits = new List<ARRaycastHit>();


    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount == 0)
        {
            return;
        }

        Touch touch = Input.GetTouch(0);

        if (arRaycastManager.Raycast(touch.position, hits, TrackableType.Planes))
        {
            Pose hitPose = hits[0].pose;

            arSessionOrigin.MakeContentAppearAt(target, hitPose.position, hitPose.rotation);
        }
    }
}

 

 arSessionOrigin.MakeContentAppearAt 을 사용하게 되면 유니티 상의 Target 객체의 좌표는 그대로 이고 ARARSessionOrigin이 Target 객체에 맞춰 이동하게 됩니다.

AR을 할때 중요한 이슈이니 꼭 기억합시다.