Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Unity 2022.2 is now available as the latest Tech release.
    Dismiss Notice
  3. We are making some changes to the DOTS forums.
    Dismiss Notice
  4. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Resolved AR Foundation: How to make 3D model facing the camera

Discussion in 'AR' started by zedoppa, May 17, 2022.

  1. zedoppa

    zedoppa

    Joined:
    Feb 26, 2020
    Posts:
    1
    First of all, I want to state that I'm new to AR development and still learning the fundamentals. Hope you guys can give me some new knowledge about AR development. Thank you in advance!

    So, back to my main problem, I tested my app with my Samsung A30 and everything works fine. But the problem is that I want to make the 3d model facing the camera, because whenever I instantiate the object, it face the other direction and not towards the camera.

    Here is my object placement script:

    Code (CSharp):
    1.  
    2. void UpdatePlacementIndicator()
    3.     {
    4.         if (spawnedObject == null && placementPoseIsValid)
    5.         {
    6.             placementIndicator.SetActive(true);
    7.             placementIndicator.transform.SetPositionAndRotation(placementPose.position, placementPose.rotation);
    8.         }
    9.         else
    10.         {
    11.             placementIndicator.SetActive(false);
    12.         }
    13.     }
    14.  
    15.     void UpdatePlacementPose()
    16.     {
    17.         var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
    18.         var hits = new List<ARRaycastHit>();
    19.         aRRaycastManager.Raycast(screenCenter, hits, TrackableType.Planes);
    20.  
    21.         placementPoseIsValid = hits.Count > 0;
    22.  
    23.         if (placementPoseIsValid)
    24.         {
    25.             placementPose = hits[0].pose;
    26.         }
    27.     }
    28.  
    29.     void ARPlaceObject()
    30.     {
    31.         spawnedObject = Instantiate(objectToSpawn, placementPose.position, placementPose.rotation);
    32.     }
    33.  
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    2,090
    Try transform.LookAt
     
    zedoppa and andyb-unity like this.