Search Unity

  1. Get top assets for 50% off! Black Friday Sale 2021.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Create an AR Drawing app using ARFoundation

Discussion in 'AR/VR (XR) Discussion' started by jatreutlein, Jan 17, 2019.

  1. jatreutlein

    jatreutlein

    Joined:
    Dec 14, 2018
    Posts:
    6

    Hey guys,
    I am trying to recreate the DRAW app in this demonstration of ARFoundation as a test project, but I can't create multiple spheres in front of the camera when I move the camera. Instead, when I use this code (which I think should work), it creates a really long line of spheres projected away from the camera. The code:
    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (Input.touchCount > 0)
    4.         {
    5.             var touch = Input.GetTouch(0);
    6.  
    7.             Transform origin = transform;
    8.             Vector3 pos = new Vector3(origin.position.x, origin.position.y - 0.5f, origin.position.z + 1);
    9.             Debug.Log(origin.ToString());
    10.             GameObject spawnedObject = Instantiate(m_PlacedPrefab, pos, Quaternion.identity);      
    11.             m_SessionOrigin.MakeContentAppearAt(spawnedObject.transform, spawnedObject.transform.position, Quaternion.identity);
    12.             disablePlanes();
    13.         }
    14.     }
    I think the reason for this is because the variable origin (that is = transform) never changes, but the .MakeContentAppearAt() function moves the ARSessionOrigin in the direction of the newly created sphere each time, therefore it creates a long line of spheres going away from the camera. This obviously is not right, so what do you think needs to be changed in order for me to get the desired behaviour (to draw spheres on the screen like in the video)?
     
unityunity