Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Problem Instantiating Objects on Virtual Mesh

Discussion in 'AR/VR (XR) Discussion' started by johnluksas, May 7, 2020.

  1. johnluksas


    Apr 4, 2019
    I am currently using a zed mini camera and Unity to make an ar world drawing program. I am using the zed mini to create the mesh of the room which I then add a mesh collider in order to raycast the problem I am having is that it seems when I instantiate symbols they are not in the right orientation everytime. I want them to always instantiate them in the orientation of the prefab but they are rotated most of the time.

    if (SteamVR_Actions.default_InteractUI.GetStateDown(SteamVR_Input_Sources.RightHand))
    Debug.Log("The right hand trigger has been pressed");
    Ray rayr = new Ray(controller_r.transform.position, controller_r.transform.forward);
    RaycastHit hitr;
    if (Physics.Raycast(rayr, out hitr))
    Vector3 offsetPointr = Vector3.Lerp(hitr.point, rayr.origin, offset);
    var gor = Instantiate(BrushMat, /*hit.point + Vector3.up * .2f*/offsetPointr, Quaternion.identity /* transform*/);
    gor.transform.up = hitr.normal;
    gor.transform.localEulerAngles = new Vector3(0,180,0);
    gor.transform.parent = SymbolHolder.transform;

    This is the code I am using to do all of the symbol instantiating. Thank you very much in advance!