Search code examples
c#unity-game-enginepositionhololenssetparent

hololens setParent position changes camera lens


I am working on using the Hololens Lens Toolkit Master. The problem is that when you set the SetParent of the lens camera, the camera position of the lens becomes the same as the position of the parent.

For example, if A's position is 0, 0, 0 and B's position is 0, 0, 4, then A.SetParent(B.Transform) would make A's position be 0, 0, -4.

This is also true on Unity Editor.

However, if you build on hololens and run A.SetParent(B.Transform), the position of A will be 0, 0, 4.

I have no idea why this happens ...

I want 0, 0, -4 !!


Solution

  • Generally speaking the parent of the main Camera is the scene itself, you cannot go higher, so the parent is the camera, unless your camera is inside another game object. Also remember too, that with the Hololens, the camera is the stable position everything else needs to move in relation to the camera, not the other way around.

    Update: So the main camera in hololens applications is like the character camera in a first person shooter, however its not the camera that moves its the world and the application is not in control of the main camera, in an FPS, you control the character either with a controller, or keyboard. The difference here is that the main camera is controlled by the hololens, 0,0,0,0 is the fixed main camera point and never changes, what happens is that the detection cameras in the hololens update position based on spatial mapping routines in the device, so changes to the position of the main camera will have unexpected results. If you want to change the point of view, I would recommend that you create a new camera and transfer the view to the new camera and move that camera, and the revert back to the main camera when you want to switch it back. This new camera cannot be a child of the main camera. One caveat is that I have never tried this, and is offered as a possible solution, I do not know if it will work or not.