Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
2.98k stars 1.11k forks source link

[Bug] ARFaceManager face.vertices doesn't work #1089

Closed curiousbee2020 closed 1 year ago

curiousbee2020 commented 1 year ago

I'm using the ARFaceManager to draw an object at a point but it never works:

        arFaceManager = GetComponent<ARFaceManager>();
        foreach (var face in arFaceManager.trackables) {
            Vector3 somePosition = face.vertices[8];
            Debug.Log("Some position =========== " + somePosition + "============" + face.transform.position);
            Instantiate(ArPrefab, somePosition, face.transform.rotation).SetActive(true);
        }    

If I replace somePosition with face.transform.position, it works, but that's not what I want. I want to instantiate it at the position I find from face.vertices. It never instantiates at any position other than face.transform.position.

I tried setting the parent, but that doesn't work either:

            GameObject obj = Instantiate(ArPrefab);
            obj.transform.parent = face.transform;
            obj.transform.position = face.vertices[8];
            obj.transform.rotation = face.transform.rotation;
            obj.SetActive(true);

It's not just vertices[x] that doesn't work, face.leftEye or face.rightEye doesn't work either.

Any ideas?

tdmowrer commented 1 year ago

According to the docs:

Vertices are provided in face space, that is, relative to this ARFace's local position and rotation.

Try using obj.transform.localPosition instead.

curiousbee2020 commented 1 year ago

Hey thanks a ton @tdmowrer! That worked! Appreciate your help and everything you do for the community :)

tdmowrer commented 1 year ago

No problem. Glad that worked :)