Search Unity

Question How to set placement indicator to set a placement in real world

Discussion in 'Cinemachine' started by Ashish_1003, Jan 18, 2023.

  1. Ashish_1003

    Ashish_1003

    Joined:
    Dec 5, 2022
    Posts:
    2
    void Update()
    {
    if(instantiatedModel==null && placementPoseIsValid && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
    {
    armodel();
    }
    UpdatePlacementPose();
    UpdatePlacementIndicator();

    }


    void UpdatePlacementIndicator()
    {

    if(instantiatedModel==null && placementPoseIsValid)
    {
    placementIndicator.SetActive(true);
    placementIndicator.transform.SetPositionAndRotation(PlacementPose.position, PlacementPose.rotation);
    }
    else
    {
    placementIndicator.SetActive(false);

    }
    }

    void UpdatePlacementPose()
    {
    var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));
    var hits = new List<ARRaycastHit>();
    aRRaycastManager.Raycast(screenCenter, hits, TrackableType.Planes);

    placementPoseIsValid = hits.Count > 0;
    if(placementPoseIsValid)
    {
    PlacementPose = hits[0].pose;
    }
    }
     
  2. Ashish_1003

    Ashish_1003

    Joined:
    Dec 5, 2022
    Posts:
    2
    I am using this code but the issue is when i set it its shaking i want it to be a part of real world like its there its shaking and sometime the model is instantiated in air like there is a gape in 3d model and surface even though i set the placement indicator right
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Probably the placement is happening before the camera gets positioned, so it is using stale camera data from the previous frame.

    The solution is to make sure your placement code runs after CinemachineBrain.LateUpdate. You can do this either by setting a sufficiently high execution order on your script (and moving the code to LateUpdate), or by hooking into CinemachineCore.CameraUpdatedEvent, which is fired after the camera is positioned.