@ramuramuramu

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Unity、Vuforia マーカー認識によって表示したオブジェクトを固定する方法

マーカー認識によって表示したオブジェクトを固定する

UnityとVuforiaを使用してマーカー(写真)を認識し、AR表示したオブジェクトを表示した場所に固定する方法を教えてください。

発生している問題・エラー

マーカーの少し右側にオブジェクトを表示したいのですが、そのオブジェクトを見ようとカメラを動かすと、マーカーがカメラから外れて表示したオブジェクトが動いてしまいます。
DeviceTrackerを試しましたが、完全に固定されず少し動いてしまいます。

自分で試したこと

下のように、ボタンをクリックした瞬間のオブジェクトの位置を記録し、マーカーに依存しない、まったく同じオブジェクトを出そうともしましたがうまくいきませんでした。

本当に初心者なので変なプログラムだと思いますが、よろしくお願いします。


public class Test_Plane : MonoBehaviour
{


    
    public Button button;

    public GameObject plane;//マーカーによって表示するオブジェクト
    public GameObject planeObject1;//新たに表示させるオブジェクト

    public float plane_bornPos_x;
    public float plane_bornPos_y;
    public float plane_bornPos_z;

    

    void Start()
    {
        button.onClick.AddListener(click);
        planeObject1.SetActive(false);
    }

    

    

    void click()
    {
        MeshRenderer ar_plane = plane.GetComponent<MeshRenderer>();

            Transform wasTransform = plane.transform;
            Vector3 pos = wasTransform.position;

            pos.x = plane.transform.position.x;
            pos.y = plane.transform.position.y;
            pos.z = plane.transform.position.z;
            


        

        plane.SetActive(false);

        Transform myTransform = planeObject1.transform;
        Vector3 now_pos = myTransform.position;
        now_pos.x = pos.x;
        now_pos.y = pos.y;
        now_pos.z = pos.z;
        myTransform.position = now_pos;

        planeObject1.SetActive(true);



        var rb = planeObject1.GetComponent<Rigidbody>();
        rb.constraints = RigidbodyConstraints.FreezeAll;
    }
}

0 likes

No Answers yet.

Your answer might help someone💌