0

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 !!

Programmer
  • 121,791
  • 22
  • 236
  • 328
Bert Hu
  • 9
  • 7

2 Answers2

0

There are two overloads for the SetParent function:

SetParent(Transform parent)

SetParent(Transform parent, bool worldPositionStays);

The first one uses true for the parameter as default. Use the second function and pass false to it to force the object use its location position when setting its parent.

A.SetParent(B.Transform, false);
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Thanks for the answer. But I did it the way, but the result was the same. It has changed to the same position as the parent. – Bert Hu Oct 17 '17 at 06:07
  • Sad that I don't have hololens and cannot replicate this issue. Usually, the position issue after calling the `SetParent` function is solved by providing the second parameter. Modify your question with a screenshot of the camera value that is always changing maybe someone can figure out the issue. – Programmer Oct 17 '17 at 06:18
0

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.

Kelso Sharp
  • 972
  • 8
  • 12
  • Thank you for your reply. I did not put the camera as a child, I created a dummy, put the dummy as a child, and dummy as a reference to the location of the camera. – Bert Hu Nov 09 '17 at 02:17
  • But I still do not understand. This is the same logic, but it works fine on the Asus Zhenphone AR camera, but I do not know what makes it so that it does not work properly on a hololens camera. – Bert Hu Nov 09 '17 at 02:20
  • Hololens is a completely different animal, due to the fact the your vision while using is not occluded, so how the cameras work is different. Its essentially the same answer, the main camera is always 0,0,0,0 its the world that moves, not the camera. When you start changing the position of the main camera, you are actually changing the position of the person's view point, Which is a expected to be a fixed point in space, you do not want to do move that when using the hololens – Kelso Sharp Nov 22 '17 at 17:36