Search Unity

Setting world scale without affecting physics

Discussion in 'AR' started by kexar66, Oct 11, 2017.

  1. kexar66

    kexar66

    Joined:
    Feb 27, 2013
    Posts:
    48
    Hi,
    I want to be able to scale up / down the scale of AR scene. How can I setup the scale for a whole AR scene without affecting physics? When I set scale of root GameObject it breaks physics (wheel colliders).

    Thanks
     
  2. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Great question! I just gave a talk about this last week at Unite Austin. The talk and sample code will be posted next week, but the short answer is: do not scale your content (because physics will be affected, for example); instead scale all positional information coming from the device. This includes the position of the camera, the plane positions, boundaries, and extents. The easiest way to do this is to put the camera and all GameObjects generated by the device (e.g. TrackedPlanes) under the same parent GameObject, and apply scale to that. So your hierarchy might be

    AR Root
    Camera [Components: TrackedPoseDriver, SessionComponent]
    AR Controller [Components: HelloARController]
    If you then scale the "AR Root" GameObject, then it should scale the camera and visual representation of the planes. Note, however, that it hit tests within ARCore won't be aware of the scale, so you'll need to remove the scale from your raycast input and then rescale the result.

    Hope that makes sense! Let me know if you have any questions.

    Cheers,
    Tim
     
    CarinaMclane and HenryAsh like this.
  3. mattrified_

    mattrified_

    Joined:
    Jul 17, 2013
    Posts:
    32
    Quick follow-up question. Does the local positions / rotations of the Camera and ARController matter before trying this scaling method? Do they need to be at [0,0,0] and identity?
     
  4. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    For the camera, that depends on whether you check the "Use relative transform" checkbox on the TrackedPoseDriver. If it is checked, then it remembers the initial position+rotation ("pose") and makes the final pose relative to that initial pose.

    For the ARController, the HelloARController spawns in plane prefabs using itself as the parent, so its position+rotation would also matter.
     
  5. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Let me just clarify: the initial position+rotation matters because it affects things in the way I mentioned above, but scale should still work (fingers crossed; I haven't tried this specific setup).
     
  6. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi @timmunity

    You said 'The talk and sample code will be posted next week' have you a link to this please, thanks.
     
  7. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Arkade and Griffo like this.
  8. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
  9. CarinaMclane

    CarinaMclane

    Joined:
    Mar 12, 2014
    Posts:
    23
    Ha, thanks for this. Got myself in a right pickle scaling content and (attempting to) correct for physics with our first play with ARCore a few months back.
     
  10. kbabilinski

    kbabilinski

    Joined:
    Jul 12, 2012
    Posts:
    19
  11. jimmya

    jimmya

    Joined:
    Nov 15, 2016
    Posts:
    793
    Griffo likes this.
  12. tehpro_unity

    tehpro_unity

    Joined:
    Oct 9, 2018
    Posts:
    3
  13. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605