Search Unity

ARCore 1.4.1 Align rectangle pararell to floor

Discussion in 'AR' started by daw_it, Sep 3, 2018.

  1. daw_it

    daw_it

    Joined:
    Sep 3, 2018
    Posts:
    3
    How can I set rotation of the placed on vertical plane object to make its bottom side pararell to floor? At the moment vertically placed objects are sticky to the wall but have random rotation. I have been trying to set object on horizontal plane and then adjust vetical objects vector forward to horizontal objects vector up. That seems to work somehow but multiple objects apart of being pararell to each other are rotated in christmas tree shape. Important thing - I want to rotate it relative to real world, not to bottom of the screen.

    Code (CSharp):
    1. VerticallyPlacedObject.transform.forward = HorizontallyPlacedObject.transform.up;
    What I want:


    What I get:
     
    Last edited: Sep 3, 2018
    Christin2015 likes this.
  2. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    The basis you drew in "What I want" implies a right handed coordinate system, while Unity uses a left handed one, so you can't achieve a transform like that. If you flip one of the vectors (eg, make "forward" point away from the floor rather than towards it), then that is possible.

    You might be looking for Quaternion.LookRotation, which takes a forward and an up. Forward in this case might point away from the floor and "up" would be the plane's normal. That would give you what you describe, if I understand your intent correctly.
     
  3. daw_it

    daw_it

    Joined:
    Sep 3, 2018
    Posts:
    3
    I am placing rectangular shape object. I would like to that object bottom side perpendicular to floor. Way that You pointed didn't work. Perhaps there is way to do it without placing another object on floor at the very begining?
     
  4. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Could you be more specific? What was the result? Could you post some code?

    You should not need to first place an object on the floor. Here's what I was thinking:

    Code (CSharp):
    1. var placedObjectForward = Vector3.up;
    2. var placedObjectUp = normalToPlane;
    3. VerticallyPlacedObject.transform.rotation = Quaternion.LookRotation(placedObjectForward, placedObjectUp);
     
    Christin2015 likes this.
  5. daw_it

    daw_it

    Joined:
    Sep 3, 2018
    Posts:
    3
    Thanks, it worked.
     
  6. heyfrey

    heyfrey

    Joined:
    Jun 26, 2018
    Posts:
    7
    i'm working with the new ar-foundation-samples and facing almost the same problem right now but only on Android. If i build the exactly same scene (SampleUXScene) to both platforms (iOS & Android)...so on iOS it's working like expected (see picture "what i want") and on Android something went wrong like on the picture "what i get". The up-vector is facing the Camera but it rotates also around the up-axis!
    The same happens also placing an object on an horizontal plane!
    So what's the difference between iOS and Android? Is Android or ArCore interpreting something wrong? Because on iOS it's working correctly! Any ideas to fix this problem?

    This is the code to place an object on a plane...
    Code (CSharp):
    1.  
    2. void Update()
    3.     {
    4.         if (Input.touchCount > 0)
    5.         {
    6.             Touch touch = Input.GetTouch(0);
    7.  
    8.             if (touch.phase == TouchPhase.Began)
    9.             {
    10.                 if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinInfinity))
    11.                 {
    12.                     Pose hitPose = s_Hits[0].pose;
    13.                    
    14.                     spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
    15.                    
    16.  
    17.                     if (onPlacedObject != null)
    18.                     {
    19.                         onPlacedObject();
    20.                     }
    21.                 }
    22.             }
    23.         }
    24.     }